TimeUnit Enum枚举
2021-01-14 03:11
                         标签:fine   convert   odi   mat   var   mem   available   follow   font    所在包:   微秒为千分之一毫秒, 毫秒为千分之一秒, 一分钟为六十秒, 一小时为六十分钟, 一天为二十四小时。     A  时间单元主要用于通知基于时间的方法如何解释给定的时间参数。例如,如果锁不可用,下面的代码将在50毫秒内超时:  while this code will timeout in 50 seconds: 而这段代码将在50秒内超时:   Note however, that there is no guarantee that a particular timeout implementation will be able to notice the passage of time at the same granularity as the given  但是请注意,并不能保证特定的超时实现能够注意到与给定时间单位相同粒度的时间流逝。 Since:  1.5      Method and Description 方法描述   TimeUnit Enum枚举 标签:fine   convert   odi   mat   var   mem   available   follow   font    原文地址:https://www.cnblogs.com/LinQingYang/p/12943863.html
public enum TimeUnit
extends Enum
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.TimeUnit does not maintain time information, but only helps organize and use time representations that may be maintained separately across various contexts.TimeUnit 表示给定单元粒度的时间段,并提供实用程序方法来跨单元转换,以及在这些单元中执行计时和延迟操作。TimeUnit 不维护时间信息,但只帮助组织和使用可能在不同上下文中单独维护的时间表示。TimeUnit is mainly used to inform time-based methods how a given timing parameter should be interpreted. For example, the following code will timeout in 50 milliseconds if the lock is not available:
public enum Lock lock = ...; 
if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...
 Lock lock = ...; if (lock.tryLock(50L, TimeUnit.SECONDS)) ...TimeUnit.
Enum Constant Summary(枚举常量摘要)
Enum Constant and Description 
枚举常量和描述
 
 
DAYS
 
 
HOURS
 
 
MICROSECONDS
 
 
MILLISECONDS
 
 
MINUTES
 
 
NANOSECONDS
 
 
SECONDS
Method Summary(方法总结)
所有方法、静态方法、实例方法、具体方法
 
Modifier and Type 
修饰符和类型
 
 
long
 
convert(long sourceDuration, TimeUnit sourceUnit)
 
void
 
sleep(long timeout)
Thread.sleep using this time unit.Thread.sleep线程休眠。
 
void
 
timedJoin(Thread thread, long timeout)
Thread.join using this time unit.Thread.join。
 
void
 
timedWait(Object obj, long timeout)
Object.wait using this time unit.Thread.wait。
 
long
 
toDays(long duration)
DAYS.convert(duration, this).DAYS.convert(duration, this)。
 
long
 
toHours(long duration)
HOURS.convert(duration, this).HOURS.convert(duration, this)。
 
long
 
toMicros(long duration)
MICROSECONDS.convert(duration, this).MICROSECONDS.convert(duration, this)。
 
long
 
toMillis(long duration)
MILLISECONDS.convert(duration, this).MILLISECONDS.convert(duration, this)。
 
long
 
toMinutes(long duration)
MINUTES.convert(duration, this).MINUTES.convert(duration, this)。
 
long
 
toNanos(long duration)
NANOSECONDS.convert(duration, this).
 
long
 
toSeconds(long duration)
SECONDS.convert(duration, this).
 
static TimeUnit
 
valueOf(String name)
 
static TimeUnit[]
 
values()