splitting seconds into Hr, Min and Sec, and formating number

Discussion in 'Java' started by Robocop, Feb 21, 2004.

  1. Robocop

    Robocop Guest

    Hi folks, i wanna split seconds into hours, minutes and seconds

    if I have: 35800 seconds
    I want to have output as follows

    Orbital Period = 23 hours, 56 minutes, and 29.0 seconds

    *Formating number*

    if i get 34.87234524 how to formate it to get 34.87 in output only
    upto two decimal places! , I tried using Math.round etc doesn't work!

    Thanks very much for help!!! :)
     
    Robocop, Feb 21, 2004
    #1
    1. Advertising

  2. Robocop

    P.Hill Guest

    Robocop wrote:
    > Hi folks, i wanna split seconds into hours, minutes and seconds
    > *Formating number*


    Yup you are on the right track try java.text.SimpleDateFormat
    push **MILLI** seconds into a java.util.Date use an appropriate for
    DateFormat mySimpleFormat = new SimpleDateFormat( "somethign with h's, m's and
    s' and maybe some colons" );
    System.out.println( mySimpleDateFormat.format( new Date( mySeconds * 1000 ) ) );

    Close enough?

    Try the javaDocs.

    -Paul
     
    P.Hill, Feb 21, 2004
    #2
    1. Advertising

  3. Robocop wrote:
    > *Formating number*
    >
    > if i get 34.87234524 how to formate it to get 34.87 in output only
    > upto two decimal places! , I tried using Math.round etc doesn't work!


    Use java.text.DecimalFormat.

    --
    Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Feb 21, 2004
    #3
  4. Robocop

    Sean Berry Guest

    This may not be what you are looking for at all... but may help.

    Cast your seconds to be an int.
    Then
    int hours = seconds/3600
    // equals 9
    int tempminutes = seconds%3600
    // equals 3400
    int minutes = tempminutes/60
    // equlas 56
    int seconds = tempminutes%60
    // eqals 40
    so you get 35800 seconds = 9 hours, 56 minutes, 40 seconds.
    Format it in any way you like

    > Orbital Period = 23 hours, 56 minutes, and 29.0 seconds


    This corresponds to 86189 seconds... not 35800.




    Robocop <> wrote in message
    news:...
    > Hi folks, i wanna split seconds into hours, minutes and seconds
    >
    > if I have: 35800 seconds
    > I want to have output as follows
    >
    > Orbital Period = 23 hours, 56 minutes, and 29.0 seconds
    >
    > *Formating number*
    >
    > if i get 34.87234524 how to formate it to get 34.87 in output only
    > upto two decimal places! , I tried using Math.round etc doesn't work!
    >
    > Thanks very much for help!!! :)
     
    Sean Berry, Feb 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The DUDE
    Replies:
    3
    Views:
    581
    code learner
    Dec 24, 2010
  2. Summu82
    Replies:
    5
    Views:
    870
    Richard Heathfield
    Jun 7, 2006
  3. Richard Heesbeen

    Webservice handling amount of requests per sec/min.......

    Richard Heesbeen, May 28, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    176
    Bruce Johnson [C# MVP]
    May 28, 2005
  4. Michael Tan
    Replies:
    32
    Views:
    998
    Ara.T.Howard
    Jul 21, 2005
  5. x1
    Replies:
    4
    Views:
    142
Loading...

Share This Page