• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert time units (not Date conversion)

 
Peter Fat
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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!
 
Maneesh Godbole
Saloon Keeper
Posts: 11176
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you try searching? The java API has a class that may help you with time units...
 
Campbell Ritchie
Sheriff
Pie
Posts: 50182
79
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 50182
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it is nearly as fast to write code from scratch for something this simple.
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic