TimeUnit.SECONDS
时间: 2024-05-05 20:15:34 浏览: 90
时分秒.ms11
TimeUnit.SECONDS is a constant in Java that represents time durations in seconds. It is used in conjunction with the TimeUnit class to perform time-based calculations, such as converting between different units of time or delaying the execution of code for a specific amount of time.
Example usage:
```
long seconds = 10;
long milliseconds = TimeUnit.SECONDS.toMillis(seconds); // convert seconds to milliseconds
Thread.sleep(TimeUnit.SECONDS.toMillis(5)); // delay execution of code for 5 seconds
```
In the above example, we convert 10 seconds to milliseconds using the `toMillis()` method of the TimeUnit class. We also delay the execution of code for 5 seconds using the `sleep()` method and passing in the number of milliseconds to wait, which is obtained by converting 5 seconds to milliseconds using `toMillis()`.
阅读全文