Duration
Represents the amount of time one instant of time is away from another instant.
A negative duration is possible in a situation when the second instant is earlier than the first one.
The type can store duration values up to ±146 years with nanosecond precision, and up to ±146 million years with millisecond precision. If a duration-returning operation provided in kotlin.time
produces a duration value that doesn't fit into the above range, the returned Duration
is infinite.
An infinite duration value Duration.INFINITE can be used to represent infinite timeouts.
To construct a duration use either the extension function toDuration, or the extension properties hours, minutes, seconds, and so on, available on Int, Long, and Double numeric types.
To get the value of this duration expressed in a particular duration units use the functions toInt, toLong, and toDouble or the properties inWholeHours, inWholeMinutes, inWholeSeconds, inWholeNanoseconds, and so on.
Since Kotlin
1.6Properties
Returns the absolute value of this value. The returned value is always non-negative.
The value of this duration expressed as a Long number of hours.
The value of this duration expressed as a Long number of microseconds.
The value of this duration expressed as a Long number of milliseconds.
The value of this duration expressed as a Long number of minutes.
The value of this duration expressed as a Long number of nanoseconds.
The value of this duration expressed as a Long number of seconds.
Functions
Splits this duration into seconds, and nanoseconds and executes the given action with these components. The result of action is returned as the result of this function.
Splits this duration into minutes, seconds, and nanoseconds and executes the given action with these components. The result of action is returned as the result of this function.
Splits this duration into hours, minutes, seconds, and nanoseconds and executes the given action with these components. The result of action is returned as the result of this function.
Splits this duration into days, hours, minutes, seconds, and nanoseconds and executes the given action with these components. The result of action is returned as the result of this function.
Returns an ISO-8601 based string representation of this duration.
Converts kotlin.time.Duration value to java.time.Duration value.
Returns a string representation of this duration value expressed as a combination of numeric components, each in its own unit.
Returns a string representation of this duration value expressed in the given unit and formatted with the specified decimals number of digits after decimal point.