• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert time units (not Date conversion)

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have a time interval of, for example, 90632 secons, and I want to present this in the format: 1 day 1 hour 10 minutes and 32 seconds.

Is there anything that can help me with this? I prefer to use a already existing framework, than to write the code from scratch for this.

Thanks!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A day has 24 hours.
An hour has 60 minutes.
A minute has 60 seconds.
Should be straight forward calculation.
 
Peter Fat
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seriously? A day has 24 hours?! Wow...

Obviously I know how to convert time. But I prefer to reuse already existing code who does it. I'm gonna deduce from your answer, that you know none. Thanks anyway.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you try searching? The java API has a class that may help you with time units...
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We probably don’t use that sort of class this time of year. In November we get the tyros, who have to do that sort of thing with arithmetic. Of course you can remind yourself of the arithmetical operators, and work out which can convert seconds to minutes and seconds. Once you have worked that out you repeat the procedure for hours ...
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it is nearly as fast to write code from scratch for something this simple.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm with Fred on this one. The java.util.concurrent package has an enum that's designed for just these kinds of things.
reply
    Bookmark Topic Watch Topic
  • New Topic