Package kotlinx.datetime

Types

Link copied to clipboard
interface Clock

A source of Instant values.

Link copied to clipboard
class DatePeriod : DateTimePeriod

A special case of DateTimePeriod that only stores date components and has all time components equal to zero.

Link copied to clipboard
class DateTimeArithmeticException : RuntimeException

Thrown by date-time arithmetic operations if the result can not be computed or represented.

Link copied to clipboard
sealed class DateTimePeriod

A difference between two instants, decomposed into date and time components.

Link copied to clipboard
sealed class DateTimeUnit

A unit for measuring time.

Link copied to clipboard
expect enum DayOfWeek : Enum<DayOfWeek>

The enumeration class representing the days of the week.

actual enum DayOfWeek : Enum<DayOfWeek>
actual typealias DayOfWeek = DayOfWeek
actual enum DayOfWeek : Enum<DayOfWeek>
Link copied to clipboard
expect class FixedOffsetTimeZone : TimeZone

A time zone that is known to always have the same offset from UTC.

actual class FixedOffsetTimeZone : TimeZone
actual class FixedOffsetTimeZone : TimeZone
actual class FixedOffsetTimeZone : TimeZone
Link copied to clipboard
class IllegalTimeZoneException : IllegalArgumentException

Thrown when attempting to construct a TimeZone with an invalid ID.

Link copied to clipboard
expect class Instant : Comparable<Instant>

A moment in time.

actual class Instant : Comparable<Instant>
actual class Instant : Comparable<Instant>
actual class Instant : Comparable<Instant>
Link copied to clipboard
expect class LocalDate(    year: Int,     monthNumber: Int,     dayOfMonth: Int) : Comparable<LocalDate>

The date part of LocalDateTime.

actual class LocalDate(    year: Int,     monthNumber: Int,     dayOfMonth: Int) : Comparable<LocalDate>
actual class LocalDate(    year: Int,     monthNumber: Int,     dayOfMonth: Int) : Comparable<LocalDate>
actual class LocalDate(    val year: Int,     val monthNumber: Int,     val dayOfMonth: Int) : Comparable<LocalDate>
Link copied to clipboard
expect class LocalDateTime(date: LocalDate, time: LocalTime) : Comparable<LocalDateTime>

The representation of a specific civil date and time without a reference to a particular time zone.

actual class LocalDateTime(date: LocalDate, time: LocalTime) : Comparable<LocalDateTime>
actual class LocalDateTime(date: LocalDate, time: LocalTime) : Comparable<LocalDateTime>
actual class LocalDateTime(val date: LocalDate, val time: LocalTime) : Comparable<LocalDateTime>
Link copied to clipboard
expect class LocalTime(    hour: Int,     minute: Int,     second: Int = 0,     nanosecond: Int = 0) : Comparable<LocalTime>

The time part of LocalDateTime.

actual class LocalTime(    hour: Int,     minute: Int,     second: Int,     nanosecond: Int) : Comparable<LocalTime>
actual class LocalTime(    hour: Int,     minute: Int,     second: Int,     nanosecond: Int) : Comparable<LocalTime>
actual class LocalTime(    val hour: Int,     val minute: Int,     val second: Int,     val nanosecond: Int) : Comparable<LocalTime>
Link copied to clipboard
expect enum Month : Enum<Month>

The enumeration class representing the 12 months of the year.

actual enum Month : Enum<Month>
actual typealias Month = Month
actual enum Month : Enum<Month>
Link copied to clipboard
expect open class TimeZone

A time zone, provides the conversion between Instant and LocalDateTime values using a collection of rules specifying which LocalDateTime value corresponds to each Instant.

actual open class TimeZone
actual open class TimeZone
actual open class TimeZone
Link copied to clipboard
expect class UtcOffset

An offset from UTC.

actual class UtcOffset
actual class UtcOffset
actual class UtcOffset

Functions

Link copied to clipboard
fun Clock.asTimeSource(): TimeSource

Returns a TimeSource that uses this Clock to mark a time instant and to find the amount of time elapsed since that mark.

Link copied to clipboard
fun UtcOffset.asTimeZone(): FixedOffsetTimeZone

Returns the fixed-offset time zone with the given UTC offset.

Link copied to clipboard
fun LocalTime.atDate(date: LocalDate): LocalDateTime

Combines this time's components with the specified LocalDate components into a LocalDateTime value.

fun LocalTime.atDate(    year: Int,     monthNumber: Int,     dayOfMonth: Int = 0): LocalDateTime
fun LocalTime.atDate(    year: Int,     month: Month,     dayOfMonth: Int = 0): LocalDateTime

Combines this time's components with the specified date components into a LocalDateTime value.

Link copied to clipboard
expect fun LocalDate.atStartOfDayIn(timeZone: TimeZone): Instant

Returns an instant that corresponds to the start of this date in the specified timeZone.

actual fun LocalDate.atStartOfDayIn(timeZone: TimeZone): Instant
actual fun LocalDate.atStartOfDayIn(timeZone: TimeZone): Instant
actual fun LocalDate.atStartOfDayIn(timeZone: TimeZone): Instant
Link copied to clipboard
fun LocalDate.atTime(time: LocalTime): LocalDateTime

Combines this date's components with the specified LocalTime components into a LocalDateTime value.

fun LocalDate.atTime(    hour: Int,     minute: Int,     second: Int = 0,     nanosecond: Int = 0): LocalDateTime

Combines this date's components with the specified time components into a LocalDateTime value.

Link copied to clipboard
fun DateTimePeriod(    years: Int = 0,     months: Int = 0,     days: Int = 0,     hours: Int = 0,     minutes: Int = 0,     seconds: Int = 0,     nanoseconds: Long = 0): DateTimePeriod

Constructs a new DateTimePeriod. If all the time components are zero, returns a DatePeriod.

Link copied to clipboard
fun DayOfWeek(isoDayNumber: Int): DayOfWeek

Returns the DayOfWeek instance for the given ISO-8601 week day number. Monday is 1, Sunday is 7.

Link copied to clipboard
expect fun LocalDate.daysUntil(other: LocalDate): Int

Returns the number of whole days between two dates.

fun Instant.daysUntil(other: Instant, timeZone: TimeZone): Int

Returns the number of whole days between two instants in the specified timeZone.

actual fun LocalDate.daysUntil(other: LocalDate): Int
actual fun LocalDate.daysUntil(other: LocalDate): Int
actual fun LocalDate.daysUntil(other: LocalDate): Int
Link copied to clipboard
fun Instant.minus(unit: DateTimeUnit.TimeBased): Instant

Returns an instant that is the result of subtracting one unit from this instant.

operator fun LocalDate.minus(period: DatePeriod): LocalDate

Returns a date that is the result of subtracting components of DatePeriod from this date. The components are subtracted in the order from the largest units to the smallest, i.e. from years to days.

fun LocalDate.minus(unit: DateTimeUnit.DateBased): LocalDate

Returns a LocalDate that is the result of subtracting one unit from this date.

operator fun LocalDate.minus(other: LocalDate): DatePeriod

Returns a DatePeriod representing the difference between other and this dates.

fun Instant.minus(value: Int, unit: DateTimeUnit.TimeBased): Instant
fun Instant.minus(value: Long, unit: DateTimeUnit.TimeBased): Instant

Returns an instant that is the result of subtracting the value number of the specified unit from this instant.

fun Instant.minus(period: DateTimePeriod, timeZone: TimeZone): Instant

Returns an instant that is the result of subtracting components of DateTimePeriod from this instant. The components are subtracted in the order from the largest units to the smallest, i.e. from years to nanoseconds.

fun Instant.minus(unit: DateTimeUnit, timeZone: TimeZone): Instant

Returns an instant that is the result of subtracting one unit from this instant in the specified timeZone.

fun Instant.minus(other: Instant, unit: DateTimeUnit.TimeBased): Long

Returns the whole number of the specified time units between other and this instants.

fun Instant.minus(other: Instant, timeZone: TimeZone): DateTimePeriod

Returns a DateTimePeriod representing the difference between other and this instants.

expect fun LocalDate.minus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
fun LocalDate.minus(value: Long, unit: DateTimeUnit.DateBased): LocalDate

Returns a LocalDate that is the result of subtracting the value number of the specified unit from this date.

expect fun Instant.minus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
fun Instant.minus(    value: Long,     unit: DateTimeUnit,     timeZone: TimeZone): Instant

Returns an instant that is the result of subtracting the value number of the specified unit from this instant in the specified timeZone.

fun Instant.minus(    other: Instant,     unit: DateTimeUnit,     timeZone: TimeZone): Long

Returns the whole number of the specified date or time units between other and this instants in the specified timeZone.

actual fun LocalDate.minus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.minus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
actual fun LocalDate.minus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.minus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
actual fun LocalDate.minus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.minus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
Link copied to clipboard
fun Month(number: Int): Month

Returns the Month instance for the given month number. January is 1, December is 12.

Link copied to clipboard
expect fun LocalDate.monthsUntil(other: LocalDate): Int

Returns the number of whole months between two dates.

fun Instant.monthsUntil(other: Instant, timeZone: TimeZone): Int

Returns the number of whole months between two instants in the specified timeZone.

actual fun LocalDate.monthsUntil(other: LocalDate): Int
actual fun LocalDate.monthsUntil(other: LocalDate): Int
actual fun LocalDate.monthsUntil(other: LocalDate): Int
Link copied to clipboard
expect fun TimeZone.offsetAt(instant: Instant): UtcOffset

Finds the offset from UTC this time zone has at the specified instant of physical time.

actual fun TimeZone.offsetAt(instant: Instant): UtcOffset
actual fun TimeZone.offsetAt(instant: Instant): UtcOffset
actual fun TimeZone.offsetAt(instant: Instant): UtcOffset
Link copied to clipboard
fun Instant.offsetIn(timeZone: TimeZone): UtcOffset

Finds the offset from UTC the specified timeZone has at this instant of physical time.

Link copied to clipboard
expect fun LocalDate.periodUntil(other: LocalDate): DatePeriod

Returns a DatePeriod representing the difference between this and other dates.

expect fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateTimePeriod

Returns a DateTimePeriod representing the difference between this and other instants.

actual fun LocalDate.periodUntil(other: LocalDate): DatePeriod
actual fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateTimePeriod
actual fun LocalDate.periodUntil(other: LocalDate): DatePeriod
actual fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateTimePeriod
actual fun LocalDate.periodUntil(other: LocalDate): DatePeriod
actual fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateTimePeriod
Link copied to clipboard
operator fun DatePeriod.plus(other: DatePeriod): DatePeriod

Adds two DatePeriod instances.

operator fun DateTimePeriod.plus(other: DateTimePeriod): DateTimePeriod

Adds two DateTimePeriod instances.

fun Instant.plus(unit: DateTimeUnit.TimeBased): Instant

Returns an instant that is the result of adding one unit to this instant.

expect operator fun LocalDate.plus(period: DatePeriod): LocalDate

Returns a date that is the result of adding components of DatePeriod to this date. The components are added in the order from the largest units to the smallest, i.e. from years to days.

expect fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate

Returns a LocalDate that is the result of adding one unit to this date.

fun Instant.plus(value: Int, unit: DateTimeUnit.TimeBased): Instant
expect fun Instant.plus(value: Long, unit: DateTimeUnit.TimeBased): Instant

Returns an instant that is the result of adding the value number of the specified unit to this instant.

expect fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Instant

Returns an instant that is the result of adding components of DateTimePeriod to this instant. The components are added in the order from the largest units to the smallest, i.e. from years to nanoseconds.

expect fun Instant.plus(unit: DateTimeUnit, timeZone: TimeZone): Instant

Returns an instant that is the result of adding one unit to this instant in the specified timeZone.

expect fun LocalDate.plus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
expect fun LocalDate.plus(value: Long, unit: DateTimeUnit.DateBased): LocalDate

Returns a LocalDate that is the result of adding the value number of the specified unit to this date.

expect fun Instant.plus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
expect fun Instant.plus(    value: Long,     unit: DateTimeUnit,     timeZone: TimeZone): Instant

Returns an instant that is the result of adding the value number of the specified unit to this instant in the specified timeZone.

actual operator fun LocalDate.plus(period: DatePeriod): LocalDate
actual fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.plus(value: Long, unit: DateTimeUnit.TimeBased): Instant
actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Instant
actual fun Instant.plus(unit: DateTimeUnit, timeZone: TimeZone): Instant
actual fun LocalDate.plus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
actual fun LocalDate.plus(value: Long, unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.plus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
actual fun Instant.plus(    value: Long,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
actual operator fun LocalDate.plus(period: DatePeriod): LocalDate
actual fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.plus(value: Long, unit: DateTimeUnit.TimeBased): Instant
actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Instant
actual fun Instant.plus(unit: DateTimeUnit, timeZone: TimeZone): Instant
actual fun LocalDate.plus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
actual fun LocalDate.plus(value: Long, unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.plus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
actual fun Instant.plus(    value: Long,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
actual operator fun LocalDate.plus(period: DatePeriod): LocalDate
actual fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.plus(value: Long, unit: DateTimeUnit.TimeBased): Instant
actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Instant
actual fun Instant.plus(unit: DateTimeUnit, timeZone: TimeZone): Instant
actual fun LocalDate.plus(value: Int, unit: DateTimeUnit.DateBased): LocalDate
actual fun LocalDate.plus(value: Long, unit: DateTimeUnit.DateBased): LocalDate
actual fun Instant.plus(    value: Int,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
actual fun Instant.plus(    value: Long,     unit: DateTimeUnit,     timeZone: TimeZone): Instant
Link copied to clipboard
fun String.toDatePeriod(): DatePeriod

Parses the ISO-8601 duration representation as a DatePeriod.

Link copied to clipboard
fun String.toDateTimePeriod(): DateTimePeriod

Parses the ISO-8601 duration representation as a DateTimePeriod.

fun Duration.toDateTimePeriod(): DateTimePeriod

Constructs a DateTimePeriod from a Duration.

Link copied to clipboard
fun Clock.todayIn(timeZone: TimeZone): LocalDate

Returns the current date at the given time zone, according to this Clock.

Link copied to clipboard
fun String.toInstant(): Instant

Converts this string representing an instant in ISO-8601 format including date and time components and the time zone offset to an Instant value.

expect fun LocalDateTime.toInstant(timeZone: TimeZone): Instant

Returns an instant that corresponds to this civil date/time value in the specified timeZone.

expect fun LocalDateTime.toInstant(offset: UtcOffset): Instant

Returns an instant that corresponds to this civil date/time value that happens at the specified UTC offset.

actual fun LocalDateTime.toInstant(timeZone: TimeZone): Instant
actual fun LocalDateTime.toInstant(offset: UtcOffset): Instant
actual fun LocalDateTime.toInstant(timeZone: TimeZone): Instant
actual fun LocalDateTime.toInstant(offset: UtcOffset): Instant
actual fun LocalDateTime.toInstant(timeZone: TimeZone): Instant
actual fun LocalDateTime.toInstant(offset: UtcOffset): Instant
Link copied to clipboard
fun Instant.toJavaInstant(): Instant

Converts this kotlinx.datetime.Instant value to a java.time.Instant value.

Link copied to clipboard
fun LocalDate.toJavaLocalDate(): LocalDate

Converts this kotlinx.datetime.LocalDate value to a java.time.LocalDate value.

Link copied to clipboard
fun LocalDateTime.toJavaLocalDateTime(): LocalDateTime
Link copied to clipboard
fun LocalTime.toJavaLocalTime(): LocalTime

Converts this kotlinx.datetime.LocalDateTime value to a java.time.LocalTime value.

Link copied to clipboard
fun DatePeriod.toJavaPeriod(): Period

Converts this kotlinx.datetime.DatePeriod value to a java.time.Period value.

Link copied to clipboard
fun TimeZone.toJavaZoneId(): ZoneId

Converts this kotlinx.datetime.TimeZone value to a java.time.ZoneId value.

Link copied to clipboard
fun FixedOffsetTimeZone.toJavaZoneOffset(): ZoneOffset
fun UtcOffset.toJavaZoneOffset(): ZoneOffset

Converts this kotlinx.datetime.UtcOffset value to a java.time.ZoneOffset value.

Link copied to clipboard
fun Instant.toJSDate(): Date

Converts the Instant to an instance of JS Date.

Link copied to clipboard
fun Period.toKotlinDatePeriod(): DatePeriod

Converts this java.time.Period value to a kotlinx.datetime.DatePeriod value.

Link copied to clipboard
Link copied to clipboard
fun <Error class: unknown class>.toKotlinInstant(): Instant

Converts the NSDate to the corresponding Instant.

fun Date.toKotlinInstant(): Instant

Converts the JS Date to the corresponding Instant.

fun Instant.toKotlinInstant(): Instant

Converts this java.time.Instant value to a kotlinx.datetime.Instant value.

Link copied to clipboard
fun LocalDate.toKotlinLocalDate(): LocalDate

Converts this java.time.LocalDate value to a kotlinx.datetime.LocalDate value.

Link copied to clipboard
fun LocalDateTime.toKotlinLocalDateTime(): LocalDateTime
Link copied to clipboard
fun LocalTime.toKotlinLocalTime(): LocalTime

Converts this java.time.LocalTime value to a kotlinx.datetime.LocalTime value.

Link copied to clipboard
fun <Error class: unknown class>.toKotlinTimeZone(): TimeZone

Converts the NSTimeZone to the corresponding TimeZone.

fun ZoneId.toKotlinTimeZone(): TimeZone

Converts this java.time.ZoneId value to a kotlinx.datetime.TimeZone value.

Link copied to clipboard
fun ZoneOffset.toKotlinUtcOffset(): UtcOffset

Converts this java.time.ZoneOffset value to a kotlinx.datetime.UtcOffset value.

Link copied to clipboard
fun String.toLocalDate(): LocalDate

Converts this string representing a date in ISO-8601 format to a LocalDate value.

Link copied to clipboard
fun String.toLocalDateTime(): LocalDateTime

Converts this string representing a date/time value in ISO-8601 format including date and time components but without any time zone component to a LocalDateTime value.

expect fun Instant.toLocalDateTime(timeZone: TimeZone): LocalDateTime

Returns a civil date/time value that this instant has in the specified timeZone.

actual fun Instant.toLocalDateTime(timeZone: TimeZone): LocalDateTime
actual fun Instant.toLocalDateTime(timeZone: TimeZone): LocalDateTime
actual fun Instant.toLocalDateTime(timeZone: TimeZone): LocalDateTime
Link copied to clipboard
fun String.toLocalTime(): LocalTime

Converts this string representing a time value in ISO-8601 format to a LocalTime value.

Link copied to clipboard
fun Instant.toNSDate(): <Error class: unknown class>

Converts the Instant to an instance of NSDate.

Link copied to clipboard
fun LocalDate.toNSDateComponents(): <Error class: unknown class>
fun LocalDateTime.toNSDateComponents(): <Error class: unknown class>

Converts the given LocalDate to NSDateComponents.

Link copied to clipboard
fun TimeZone.toNSTimeZone(): <Error class: unknown class>

Converts the TimeZone to NSTimeZone.

Link copied to clipboard
fun Instant.until(other: Instant, unit: DateTimeUnit.TimeBased): Long

Returns the whole number of the specified time units between this and other instants.

expect fun LocalDate.until(other: LocalDate, unit: DateTimeUnit.DateBased): Int

Returns the whole number of the specified date units between this and other dates.

expect fun Instant.until(    other: Instant,     unit: DateTimeUnit,     timeZone: TimeZone): Long

Returns the whole number of the specified date or time units between this and other instants in the specified timeZone.

actual fun LocalDate.until(other: LocalDate, unit: DateTimeUnit.DateBased): Int
actual fun Instant.until(    other: Instant,     unit: DateTimeUnit,     timeZone: TimeZone): Long
actual fun LocalDate.until(other: LocalDate, unit: DateTimeUnit.DateBased): Int
actual fun Instant.until(    other: Instant,     unit: DateTimeUnit,     timeZone: TimeZone): Long
actual fun LocalDate.until(other: LocalDate, unit: DateTimeUnit.DateBased): Int
actual fun Instant.until(    other: Instant,     unit: DateTimeUnit,     timeZone: TimeZone): Long
Link copied to clipboard
expect fun UtcOffset(    hours: Int? = null,     minutes: Int? = null,     seconds: Int? = null): UtcOffset

Constructs a UtcOffset from hours, minutes, and seconds components.

actual fun UtcOffset(    hours: Int? = null,     minutes: Int? = null,     seconds: Int? = null): UtcOffset
actual fun UtcOffset(    hours: Int? = null,     minutes: Int? = null,     seconds: Int? = null): UtcOffset
actual fun UtcOffset(    hours: Int? = null,     minutes: Int? = null,     seconds: Int? = null): UtcOffset
Link copied to clipboard
expect fun LocalDate.yearsUntil(other: LocalDate): Int

Returns the number of whole years between two dates.

fun Instant.yearsUntil(other: Instant, timeZone: TimeZone): Int

Returns the number of whole years between two instants in the specified timeZone.

actual fun LocalDate.yearsUntil(other: LocalDate): Int
actual fun LocalDate.yearsUntil(other: LocalDate): Int
actual fun LocalDate.yearsUntil(other: LocalDate): Int

Properties

Link copied to clipboard
val Instant.isDistantFuture: Boolean

Returns true if the instant is Instant.DISTANT_FUTURE or later.

Link copied to clipboard
val Instant.isDistantPast: Boolean

Returns true if the instant is Instant.DISTANT_PAST or earlier.

Link copied to clipboard
val DayOfWeek.isoDayNumber: Int

The ISO-8601 number of the given day of the week. Monday is 1, Sunday is 7.

Link copied to clipboard
val Month.number: Int

The number of the Month. January is 1, December is 12.