Results 1 to 4 of 4
Thread: What is the formula?
 04302007, 06:41 PM #1Member
 Join Date
 Apr 2007
 Location
 Singapore
 Posts
 29
 Rep Power
 0
 04302007, 07:21 PM #2levent Guest
1 hour = 60 x 60 seconds
1 minute = 60 seconds
So you will first need to find hours by dividing your number to 60x60. Then you will divide the remaining seconds to 60 to find minutes and then you will assign remaining seconds as the seconds.
Something like this:
Java Code:int x = 7384; int hours = 7384/(60*60); int minutes = (7384%(60*60))/60; int seconds = (7384%(60*60))%60;
 04302007, 08:02 PM #3Member
 Join Date
 Apr 2007
 Location
 Singapore
 Posts
 29
 Rep Power
 0
Thanks! I understand now. :)
 04302007, 11:00 PM #4Senior Member
 Join Date
 Mar 2007
 Posts
 134
 Rep Power
 0
If you want to have more flexibility use convert() method from TimeUnit in Java SE 6
Please have a look at the method details
Java Code:convert public long convert(long sourceDuration, TimeUnit sourceUnit) Convert the given time duration in the given unit to this unit. Conversions from finer to coarser granularities truncate, so lose precision. For example converting 999 milliseconds to seconds results in 0. Conversions from coarser to finer granularities with arguments that would numerically overflow saturate to Long.MIN_VALUE if negative or Long.MAX_VALUE if positive. For example, to convert 10 minutes to milliseconds, use: TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES) Parameters: sourceDuration  the time duration in the given sourceUnit sourceUnit  the unit of the sourceDuration argument Returns: the converted duration in this unit, or Long.MIN_VALUE if conversion would negatively overflow, or Long.MAX_VALUE if it would positively overflow.
Similar Threads

Computing the area of a triangle using Heron's Formula
By Java Tip in forum java.langReplies: 0Last Post: 04122008, 09:39 PM
Bookmarks