Package kotlin.time

Experimental API for representing Duration values and measuring time intervals.

Types

Common
JVM
JS
Native
1.3

AbstractDoubleClock

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

abstract class AbstractDoubleClock : Clock
Common
JVM
JS
Native
1.3

AbstractLongClock

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

abstract class AbstractLongClock : Clock
Common
JVM
JS
Native
1.3

Clock

A source of time for measuring time intervals.

interface Clock
Common
JVM
JS
Native
1.3

ClockMark

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

abstract class ClockMark
Common
JVM
JS
Native
1.3

Duration

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

class Duration : Comparable<Duration>

DurationUnit

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

Common
JS
Native
1.3
enum class DurationUnit
JVM
1.3
typealias DurationUnit = TimeUnit

MonoClock

The most precise clock available in the platform.

Common
JS
1.3
object MonoClock : Clock
JVM
Native
1.3
object MonoClock : AbstractLongClock, Clock
Common
JVM
JS
Native
1.3

TestClock

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

class TestClock : AbstractLongClock
Common
JVM
JS
Native
1.3

TimedValue

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

data class TimedValue<T>

Annotations

Common
JVM
JS
Native
1.3

ExperimentalTime

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

annotation class ExperimentalTime

Extensions for External Classes

JVM
JRE8
1.3

java.time.Duration

Properties

Common
JVM
JS
Native
1.3

days

Returns a Duration equal to this Int number of days.

val Int.days: Duration

Returns a Duration equal to this Long number of days.

val Long.days: Duration

Returns a Duration equal to this Double number of days.

val Double.days: Duration
Common
JVM
JS
Native
1.3

hours

Returns a Duration equal to this Int number of hours.

val Int.hours: Duration

Returns a Duration equal to this Long number of hours.

val Long.hours: Duration

Returns a Duration equal to this Double number of hours.

val Double.hours: Duration
Common
JVM
JS
Native
1.3

microseconds

Returns a Duration equal to this Int number of microseconds.

val Int.microseconds: Duration

Returns a Duration equal to this Long number of microseconds.

val Long.microseconds: Duration

Returns a Duration equal to this Double number of microseconds.

val Double.microseconds: Duration
Common
JVM
JS
Native
1.3

milliseconds

Returns a Duration equal to this Int number of milliseconds.

val Int.milliseconds: Duration

Returns a Duration equal to this Long number of milliseconds.

val Long.milliseconds: Duration

Returns a Duration equal to this Double number of milliseconds.

val Double.milliseconds: Duration
Common
JVM
JS
Native
1.3

minutes

Returns a Duration equal to this Int number of minutes.

val Int.minutes: Duration

Returns a Duration equal to this Long number of minutes.

val Long.minutes: Duration

Returns a Duration equal to this Double number of minutes.

val Double.minutes: Duration
Common
JVM
JS
Native
1.3

nanoseconds

Returns a Duration equal to this Int number of nanoseconds.

val Int.nanoseconds: Duration

Returns a Duration equal to this Long number of nanoseconds.

val Long.nanoseconds: Duration

Returns a Duration equal to this Double number of nanoseconds.

val Double.nanoseconds: Duration
Common
JVM
JS
Native
1.3

seconds

Returns a Duration equal to this Int number of seconds.

val Int.seconds: Duration

Returns a Duration equal to this Long number of seconds.

val Long.seconds: Duration

Returns a Duration equal to this Double number of seconds.

val Double.seconds: Duration

Functions

Common
JVM
JS
Native
1.3

compareTo

operator fun ClockMark.compareTo(other: ClockMark): Int
Common
JVM
JS
Native
1.3

measureTime

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

fun measureTime(block: () -> Unit): Duration
fun Clock.measureTime(block: () -> Unit): Duration
Common
JVM
JS
Native
1.3

measureTimedValue

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.

fun <T> 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.

fun <T> Clock.measureTimedValue(
    block: () -> T
): TimedValue<T>
Common
JVM
JS
Native
1.3

minus

operator fun ClockMark.minus(other: ClockMark): Duration
Common
JVM
JS
Native
1.3

times

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

operator fun Int.times(duration: Duration): Duration
operator fun Double.times(duration: Duration): Duration
Common
JVM
JS
Native
1.3

toDuration

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

fun Int.toDuration(unit: DurationUnit): Duration

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

fun Long.toDuration(unit: DurationUnit): Duration

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

fun Double.toDuration(unit: DurationUnit): Duration
JVM
JRE8
1.3

toJavaDuration

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

fun Duration.toJavaDuration(): Duration