Ever needed a utility which converts from one unit of time to another?
Well with Java 5 and higher, you won’t have to create your own conversion routine any longer.
Say for example you wanted to specify a value in seconds but the method you need to call expects a value in milliseconds (which is a common thing in Java).
Then this would be how you can convert the value with the java.util.concurrent.TimeUnit utility.
long oneMinute = TimeUnit.SECONDS.toMillis(60);
Java 5’s TimeUnit supports conversion to and from nano, micro, milli and seconds while Java 6’s TimeUnit also supports minutes, hours and days.

No Comments so far ↓
There are no comments yet...Kick things off by filling out the form below.