Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeUnit.SECONDS.toMillis

Tags:

java

time

I did not understand the explanation at oracle, what is this piece of code actually doing?

final int maximumDelay = (int) TimeUnit.SECONDS.toMillis(1000);
like image 306
user1477955 Avatar asked Apr 30 '13 20:04

user1477955


People also ask

What is the unit of time in Java?

It supports nanoseconds, microseconds, milliseconds, seconds, minutes, hours, and days units. For these units, TimeUnit specifies corresponding enum constants: Nanoseconds: One thousandth of a microsecond. Microseconds: One thousandth of a millisecond.

What is TimeUnit seconds in Java?

public enum TimeUnit extends Enum<TimeUnit> A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units.


1 Answers

It converts 1000 seconds into milliseconds, then truncates the result from long to int.

like image 72
Barend Avatar answered Sep 22 '22 12:09

Barend