aspose file tools*
The moose likes Beginning Java and the fly likes Java code for converting seconds into Days ,Hours and Minutes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java code for converting seconds into Days ,Hours and Minutes " Watch "Java code for converting seconds into Days ,Hours and Minutes " New topic
Author

Java code for converting seconds into Days ,Hours and Minutes

Deepak Sahu
Greenhorn

Joined: Dec 08, 2009
Posts: 22
Hi Everybody can someone provide me the Java code for converting seconds into Days ,Hours and Minutes




for example


1 Day 2 Hr 20 Min =24*60*60 + 2*60*60 + 20*60= 94800 Seconds

Similarly if we input 94800, the output should be 1 Day 2 Hr 20 Min


Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

It doesn't work like that. We're NotACodeMill. What have you tried so far? What didn't work?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You know how to convert days, hours and minutes into seconds. Converting seconds into days, hours and minutes is the inverse. The only "difficult" part is the splitting of one value into three values. Any part smaller than 1 day will be hours plus minutes; any part smaller than 1 hour will be minutes.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
I would recommend the Joda-Time library
The Period and PeriodFormat classes look very relevant.
 
 
subject: Java code for converting seconds into Days ,Hours and Minutes