Package kotlin.time

Experimental API for representing Duration values and measuring time intervals.

Experimental API for representing Duration values and measuring time intervals.

Experimental API for representing Duration values and measuring time intervals.

Experimental API for representing Duration values and measuring time intervals.

Experimental API for representing Duration values and measuring time intervals.

Types

AbstractDoubleTimeSource
Link copied to clipboard
abstract class AbstractDoubleTimeSource(unit: DurationUnit) : TimeSource

An abstract class used to implement time sources that return their readings as Double values in the specified unit.

Since Kotlin

1.3
AbstractLongTimeSource
Link copied to clipboard
abstract class AbstractLongTimeSource(unit: DurationUnit) : TimeSource

An abstract class used to implement time sources that return their readings as Long values in the specified unit.

Since Kotlin

1.3
Duration
Link copied to clipboard
value class Duration : Comparable<Duration>

Represents the amount of time one instant of time is away from another instant.

Since Kotlin

1.3
DurationUnit
Link copied to clipboard
expect enum DurationUnit : Enum<DurationUnit>

The list of possible time measurement units, in which a duration can be expressed.

Since Kotlin

1.3
actual typealias DurationUnit = TimeUnit
@ExperimentalTime
actual enum DurationUnit : Enum<DurationUnit>
@ExperimentalTime
actual enum DurationUnit : Enum<DurationUnit>
ExperimentalTime
Link copied to clipboard

This annotation marks the experimental preview of the standard library API for measuring time and working with durations.

Since Kotlin

1.3
TestTimeSource
Link copied to clipboard
class TestTimeSource : AbstractLongTimeSource

A time source that has programmatically updatable readings. It is useful as a predictable source of time in tests.

Since Kotlin

1.3
TimedValue
Link copied to clipboard
data class TimedValue<T>(value: T, duration: Duration)

Data class representing a result of executing an action, along with the duration of elapsed time interval.

Since Kotlin

1.3
TimeMark
Link copied to clipboard
abstract class TimeMark

Represents a time point notched on a particular TimeSource. Remains bound to the time source it was taken from and allows querying for the duration of time elapsed from that point (see the function elapsedNow).

Since Kotlin

1.3
TimeSource
Link copied to clipboard
interface TimeSource

A source of time for measuring time intervals.

Since Kotlin

1.3

Functions

compareTo
Link copied to clipboard
inline operator fun TimeMark.compareTo(other: TimeMark): Int
measureTime
Link copied to clipboard
inline fun measureTime(block: () -> Unit): Duration
inline fun TimeSource.measureTime(block: () -> Unit): Duration

Executes the given function block and returns the duration of elapsed time interval.

Since Kotlin

1.3
measureTimedValue
Link copied to clipboard
inline fun <T> measureTimedValue(block: () -> T): TimedValue<T>

Executes the given function block and returns an instance of TimedValue class, containing both the result of the function execution and the duration of elapsed time interval.

Since Kotlin

1.3
inline fun <T> TimeSource.measureTimedValue(block: () -> T): TimedValue<T>

Executes the given block and returns an instance of TimedValue class, containing both the result of function execution and the duration of elapsed time interval.

Since Kotlin

1.3
minus
Link copied to clipboard
inline operator fun TimeMark.minus(other: TimeMark): Duration
times
Link copied to clipboard
inline operator fun Double.times(duration: Duration): Duration
inline operator fun Int.times(duration: Duration): Duration

Returns a duration whose value is the specified duration value multiplied by this number.

Since Kotlin

1.3
toDuration
Link copied to clipboard
fun Double.toDuration(unit: DurationUnit): Duration

Returns a Duration equal to this Double number of the specified unit.

Since Kotlin

1.3
fun Int.toDuration(unit: DurationUnit): Duration

Returns a Duration equal to this Int number of the specified unit.

Since Kotlin

1.3
fun Long.toDuration(unit: DurationUnit): Duration

Returns a Duration equal to this Long number of the specified unit.

Since Kotlin

1.3
toJavaDuration
Link copied to clipboard
@ExperimentalTime
inline fun Duration.toJavaDuration(): Duration

Converts kotlin.time.Duration value to java.time.Duration value.

Since Kotlin

1.3
toKotlinDuration
Link copied to clipboard
@ExperimentalTime
inline fun Duration.toKotlinDuration(): Duration

Converts java.time.Duration value to kotlin.time.Duration value.

Since Kotlin

1.3

Properties

days
Link copied to clipboard
val Int.days: Duration

Returns a Duration equal to this Int number of days.

days
Link copied to clipboard
val Long.days: Duration

Returns a Duration equal to this Long number of days.

days
Link copied to clipboard
val Double.days: Duration

Returns a Duration equal to this Double number of days.

hours
Link copied to clipboard
val Int.hours: Duration

Returns a Duration equal to this Int number of hours.

hours
Link copied to clipboard
val Long.hours: Duration

Returns a Duration equal to this Long number of hours.

hours
Link copied to clipboard
val Double.hours: Duration

Returns a Duration equal to this Double number of hours.

microseconds
Link copied to clipboard
val Int.microseconds: Duration

Returns a Duration equal to this Int number of microseconds.

microseconds
Link copied to clipboard
val Long.microseconds: Duration

Returns a Duration equal to this Long number of microseconds.

microseconds
Link copied to clipboard
val Double.microseconds: Duration

Returns a Duration equal to this Double number of microseconds.

milliseconds
Link copied to clipboard
val Int.milliseconds: Duration

Returns a Duration equal to this Int number of milliseconds.

milliseconds
Link copied to clipboard
val Long.milliseconds: Duration

Returns a Duration equal to this Long number of milliseconds.

milliseconds
Link copied to clipboard
val Double.milliseconds: Duration

Returns a Duration equal to this Double number of milliseconds.

minutes
Link copied to clipboard
val Int.minutes: Duration

Returns a Duration equal to this Int number of minutes.

minutes
Link copied to clipboard
val Long.minutes: Duration

Returns a Duration equal to this Long number of minutes.

minutes
Link copied to clipboard
val Double.minutes: Duration

Returns a Duration equal to this Double number of minutes.

nanoseconds
Link copied to clipboard
val Int.nanoseconds: Duration

Returns a Duration equal to this Int number of nanoseconds.

nanoseconds
Link copied to clipboard
val Long.nanoseconds: Duration

Returns a Duration equal to this Long number of nanoseconds.

nanoseconds
Link copied to clipboard
val Double.nanoseconds: Duration

Returns a Duration equal to this Double number of nanoseconds.

seconds
Link copied to clipboard
val Int.seconds: Duration

Returns a Duration equal to this Int number of seconds.

seconds
Link copied to clipboard
val Long.seconds: Duration

Returns a Duration equal to this Long number of seconds.

seconds
Link copied to clipboard
val Double.seconds: Duration

Returns a Duration equal to this Double number of seconds.