aspose file tools*
The moose likes Beginning Java and the fly likes Convert time units (not Date conversion) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert time units (not Date conversion)" Watch "Convert time units (not Date conversion)" New topic
Author

Convert time units (not Date conversion)

Peter Fat
Greenhorn

Joined: Oct 18, 2010
Posts: 24
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

Joined: Jul 26, 2007
Posts: 9990
    
    7

A day has 24 hours.
An hour has 60 minutes.
A minute has 60 seconds.
Should be straight forward calculation.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Peter Fat
Greenhorn

Joined: Oct 18, 2010
Posts: 24
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

Joined: Oct 02, 2003
Posts: 10916
    
  12

did you try searching? The java API has a class that may help you with time units...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Oct 13, 2005
Posts: 36508
    
  16
Actually, it is nearly as fast to write code from scratch for something this simple.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

I'm with Fred on this one. The java.util.concurrent package has an enum that's designed for just these kinds of things.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Convert time units (not Date conversion)
 
Similar Threads
What it takes to design a *good* software...
SCJP certificate
Realistic Jump algorithm
++ Operator
Passed SCEA Part 1 with 100%