Friday 7 March 2014

Other time conversion methods

Method
Description
toDays(long duration)
Equivalent to DAYS.convert(duration, this).
toHours(long duration)
Equivalent to HOURS.convert(duration, this).
toMicros(long duration)
Equivalent to MICROSECONDS.convert(duration, this).
toMillis(long duration)
Equivalent to MILLISECONDS.convert(duration, this).
toMinutes(long duration)
Equivalent to MINUTES.convert(duration, this).
toNanos(long duration)
Equivalent to NANOSECONDS.convert(duration, this).
toSeconds(long duration)
Equivalent to SECONDS.convert(duration, this).

import java.util.concurrent.TimeUnit;
public class TimeUnitEx {
    public static void main(String args[]){
       System.out.print(" 1 Day = ");
       System.out.print(TimeUnit.DAYS.toHours(1) +" Hours =");
       System.out.print(TimeUnit.DAYS.toMinutes(1) +" Minutes =");
       System.out.print(TimeUnit.DAYS.toSeconds(1) +" Seconds");
    }
}

Output
1 Day = 24 Hours =1440 Minutes =86400 Seconds


TimeUnit Conversion                                                 TimeUnit sleep                                                 Home

No comments:

Post a Comment