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. An infinite duration value Duration.INFINITE can be used to represent infinite timeouts.
The type can store duration values up to ±146 years with nanosecond precision, and up to ±146 million years with millisecond precision.
To construct a duration, use either the extension function toDuration available on Int, Long, and Double numeric types, or the Duration
companion object functions Duration.hours, Duration.minutes, Duration.seconds, and so on, taking Int, Long, or Double numbers as parameters.
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.3Types
Functions
Returns true, if the duration value is infinite.
Returns true, if the duration value is less than zero.
Returns true, if the duration value is greater than zero.
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.
Returns an ISO-8601 based string representation of this duration.
Returns the value of this duration expressed as a Long number of milliseconds.
Returns the value of this duration expressed as a Long number of nanoseconds.
Returns a string representation of this duration value expressed in the unit which yields the most compact and readable number value.
Returns the negative of this value.
Properties
Extensions
Converts kotlin.time.Duration value to java.time.Duration value.