A human readable label for this unit.
A number representing the unit's ordering in the TimeUnit
enumeration, useful for doing comparisons to find out which unit
is more coarse grained.
MINUTES.ord < DAYS.ord // true
SECONDS.ord > MICROSECONDS.org // true
Converts the given time duration in the given unit to this unit.
Conversions from finer to coarser granularities truncate, so lose
precision. For example, converting 999
milliseconds to seconds
results in 0
. Conversions from coarser to finer granularities
with arguments that would numerically overflow saturate to
Number.MAX_VALUE
if negative or MAX_VALUE
if positive.
For example, to convert 10 minutes to milliseconds, use:
MILLISECONDS.convert(10, MINUTES)
// ... or ...
MINUTES.toMillis(10)
the time duration in the given unit
the unit of the duration
argument
the converted duration in this unit, or Number.MIN_VALUE
if conversion would negatively overflow, or Number.MAX_VALUE
if it would positively overflow
Converts the given d
value to days.
Equivalent with DAYS.convert(duration, this)
.
is the converted duration
the converted duration, or Number.MAX_SAFE_INTEGER + 1
(or 2^53
) if it overflows, or Number.MIN_SAFE_INTEGER - 1
if it
underflows (or -2^53
).
Converts the given d
value to hours.
Equivalent with HOURS.convert(duration, this)
.
is the converted duration
the converted duration, or Number.MAX_SAFE_INTEGER + 1
(or 2^53
) if it overflows, or Number.MIN_SAFE_INTEGER - 1
if it
underflows (or -2^53
).
Converts the given d
value to microseconds.
Equivalent with MICROSECONDS.convert(duration, this)
.
is the converted duration
the converted duration, or Number.MAX_SAFE_INTEGER + 1
(or 2^53
) if it overflows, or Number.MIN_SAFE_INTEGER - 1
if it
underflows (or -2^53
).
Converts the given d
value to milliseconds.
Equivalent with MILLISECONDS.convert(duration, this)
.
is the converted duration
the converted duration, or Number.MAX_SAFE_INTEGER + 1
(or 2^53
) if it overflows, or Number.MIN_SAFE_INTEGER - 1
if it
underflows (or -2^53
).
Converts the given d
value to minutes.
Equivalent with MINUTES.convert(duration, this)
.
is the converted duration
the converted duration, or Number.MAX_SAFE_INTEGER + 1
(or 2^53
) if it overflows, or Number.MIN_SAFE_INTEGER - 1
if it
underflows (or -2^53
).
Converts the given d
value to nanoseconds.
Equivalent with NANOSECONDS.convert(duration, this)
.
is the converted duration
the converted duration, or Number.MAX_SAFE_INTEGER + 1
(or 2^53
) if it overflows, or Number.MIN_SAFE_INTEGER - 1
if it
underflows (or -2^53
).
Converts the given d
value to seconds.
Equivalent with SECONDS.convert(duration, this)
.
is the converted duration
the converted duration, or Number.MAX_SAFE_INTEGER + 1
(or 2^53
) if it overflows, or Number.MIN_SAFE_INTEGER - 1
if it
underflows (or -2^53
).
Override for Object.toString
.
Generated using TypeDoc
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
is an enumeration and in usage the already defined constants should be used:Example:
// Converting 10 minutes to nanoseconds MINUTES.toNanos(10) // Equivalent with the above: NANOSECONDS.convert(10, MINUTES)