TimeUnit Enum枚举

时间:2020-05-23
本文章向大家介绍TimeUnit Enum枚举,主要包括TimeUnit Enum枚举使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

所在包:

All Implemented Interfaces:
Serializable, Comparable<TimeUnit 

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.
A TimeUnit does not maintain time information, but only helps organize and use time representations that may be maintained separately across various contexts.
A nanosecond is defined as one thousandth of a microsecond,
a microsecond as one thousandth of a millisecond,
a millisecond as one thousandth of a second,
a minute as sixty seconds,
an hour as sixty minutes,
and a day as twenty four hours. 
TimeUnit 表示给定单元粒度的时间段,并提供实用程序方法来跨单元转换,以及在这些单元中执行计时和延迟操作。
TimeUnit 不维护时间信息,但只帮助组织和使用可能在不同上下文中单独维护的时间表示。
纳秒被定义为千分之一微秒,

微秒为千分之一毫秒,

毫秒为千分之一秒,

一分钟为六十秒,

一小时为六十分钟,

一天为二十四小时。  

A 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:

时间单元主要用于通知基于时间的方法如何解释给定的时间参数。例如,如果锁不可用,下面的代码将在50毫秒内超时:

public enum Lock lock = ...; 
if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...

 while this code will timeout in 50 seconds:

而这段代码将在50秒内超时:

Lock lock = ...;

if (lock.tryLock(50L, TimeUnit.SECONDS)) ...

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 TimeUnit.

但是请注意,并不能保证特定的超时实现能够注意到与给定时间单位相同粒度的时间流逝。

Since:

1.5 


Enum Constant Summary(枚举常量摘要)

Enum Constant and Description
枚举常量和描述
DAYS
Time unit representing twenty four hours
时间单元代表24小时
HOURS
Time unit representing sixty minutes
小时时间单元代表60分钟
MICROSECONDS
Time unit representing one thousandth of a millisecond
微秒时间单元代表千分之一毫秒
MILLISECONDS
Time unit representing one thousandth of a second
毫秒时间单元代表千分之一秒
MINUTES
Time unit representing sixty seconds
分钟时间单元代表60秒
NANOSECONDS
Time unit representing one thousandth of a microsecond
纳秒时间单元代表千分之一微秒
SECONDS
Time unit representing one second
时间单元代表1秒

Method Summary(方法总结)

All Methods Static Methods Instance Methods Concrete Methods 
所有方法、静态方法、实例方法、具体方法
Modifier and Type
修饰符和类型

Method and Description

方法描述

long convert(long sourceDuration, TimeUnit sourceUnit)
Converts the given time duration in the given unit to this unit.
将给定单元中的给定持续时间转换为此单元。
void sleep(long timeout)
Performs a Thread.sleep using this time unit.
使用这个时间单位执行Thread.sleep线程休眠。
void timedJoin(Thread thread, long timeout)
Performs a timed Thread.join using this time unit.
使用这个时间单位执行一次Thread.join。
void timedWait(Object obj, long timeout)
Performs a timed Object.wait using this time unit.
使用这个时间单位执行一次Thread.wait。
long toDays(long duration)
long toHours(long duration)
long toMicros(long duration)
long toMillis(long duration)
long toMinutes(long duration)
long toNanos(long duration)
long toSeconds(long duration)
static TimeUnit valueOf(String name)
Returns the enum constant of this type with the specified name.
返回具有指定名称的此类型的枚举常量。
static TimeUnit[] values()
Returns an array containing the constants of this enum type, in the order they are declared.
返回一个数组,该数组包含此枚举类型的常数,按其声明的顺序排列。

原文地址:https://www.cnblogs.com/LinQingYang/p/12943863.html