core / io.islandtime / DateTime

DateTime

(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86) class DateTime : Comparable<DateTime>

A date and time of day in an ambiguous region.

Constructors

(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

<init>

Creates a DateTime.

<init>(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0)
<init>(year: Int, monthNumber: Int, day: Int, hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0)
<init>(year: Int, dayOfYear: Int, hour: Int, minute: Int, second: Int, nanosecond: Int)

Creates a DateTime by combining a Date and Time.

<init>(date: Date, time: Time)

Properties

(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

additionalNanosecondsSinceUnixEpoch

The number of additional nanoseconds that should be applied on top of the number of seconds since the Unix epoch returned by secondsSinceUnixEpochAt.

val additionalNanosecondsSinceUnixEpoch: IntNanoseconds
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

date

The date.

val date: Date
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

dayOfMonth

The day of the month.

val dayOfMonth: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

dayOfWeek

The day of the week.

val dayOfWeek: DayOfWeek
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

dayOfYear

The day of the year.

val dayOfYear: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

hour

The hour of the day.

val hour: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

isInLeapYear

Check if this date falls within a leap year.

val isInLeapYear: Boolean
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

isLeapDay

Check if this is a leap day.

val isLeapDay: Boolean
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

lengthOfMonth

The length of the date's month in days.

val lengthOfMonth: IntDays
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

lengthOfYear

The length of the date's year in days.

val lengthOfYear: IntDays
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

minute

The minute of the hour.

val minute: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

month

The month of the year.

val month: Month
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

monthNumber

The ISO month number, from 1-12.

val monthNumber: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

nanoOfSecondsSinceUnixEpoch

val nanoOfSecondsSinceUnixEpoch: IntNanoseconds
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

nanosecond

The nanosecond of the second.

val nanosecond: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

second

The second of the minute.

val second: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

time

The time of day.

val time: Time
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

unixEpochNanoOfSecond

val unixEpochNanoOfSecond: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

year

The year.

val year: Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

yearMonth

val yearMonth: YearMonth

Functions

(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

compareTo

fun compareTo(other: DateTime): Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

component1

operator fun component1(): Date
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

component2

operator fun component2(): Time
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

copy

Returns a copy of this date-time with the values of any individual components replaced by the new values specified.

fun copy(date: Date = this.date, time: Time = this.time): DateTime
fun copy(year: Int = this.year, dayOfYear: Int = this.dayOfYear, hour: Int = this.hour, minute: Int = this.minute, second: Int = this.second, nanosecond: Int = this.nanosecond): DateTime
fun copy(year: Int = this.year, month: Month = this.month, dayOfMonth: Int = this.dayOfMonth, hour: Int = this.hour, minute: Int = this.minute, second: Int = this.second, nanosecond: Int = this.nanosecond): DateTime
fun copy(year: Int = this.year, monthNumber: Int, dayOfMonth: Int = this.dayOfMonth, hour: Int = this.hour, minute: Int = this.minute, second: Int = this.second, nanosecond: Int = this.nanosecond): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

equals

fun equals(other: Any?): Boolean
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

hashCode

fun hashCode(): Int
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

instantAt

fun instantAt(offset: UtcOffset): Instant
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

millisecondOfUnixEpochAt

The millisecond of the Unix epoch.

fun millisecondOfUnixEpochAt(offset: UtcOffset): Long
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

millisecondsSinceUnixEpochAt

The number of milliseconds relative to the Unix epoch of 1970-01-01T00:00Z at a particular offset. This is a "floor" value, so 1 nanosecond before the Unix epoch will be at a distance of 1 millisecond.

fun millisecondsSinceUnixEpochAt(offset: UtcOffset): LongMilliseconds
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

minus

Returns this date-time with period subtracted from it.

operator fun minus(period: Period): DateTimeoperator fun minus(duration: Duration): DateTime
operator fun minus(years: IntYears): DateTime
operator fun minus(years: LongYears): DateTime
operator fun minus(months: IntMonths): DateTime
operator fun minus(months: LongMonths): DateTime
operator fun minus(weeks: IntWeeks): DateTime
operator fun minus(weeks: LongWeeks): DateTime
operator fun minus(days: IntDays): DateTime
operator fun minus(days: LongDays): DateTime
operator fun minus(hours: IntHours): DateTime
operator fun minus(hours: LongHours): DateTime
operator fun minus(minutes: IntMinutes): DateTime
operator fun minus(minutes: LongMinutes): DateTime
operator fun minus(seconds: IntSeconds): DateTime
operator fun minus(seconds: LongSeconds): DateTime
operator fun minus(milliseconds: IntMilliseconds): DateTime
operator fun minus(milliseconds: LongMilliseconds): DateTime
operator fun minus(microseconds: IntMicroseconds): DateTime
operator fun minus(microseconds: LongMicroseconds): DateTime
operator fun minus(nanoseconds: IntNanoseconds): DateTime
operator fun minus(nanoseconds: LongNanoseconds): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

plus

Returns this date-time with period added to it.

operator fun plus(period: Period): DateTimeoperator fun plus(duration: Duration): DateTime
operator fun plus(years: IntYears): DateTime
operator fun plus(years: LongYears): DateTime
operator fun plus(months: IntMonths): DateTime
operator fun plus(months: LongMonths): DateTime
operator fun plus(weeks: IntWeeks): DateTime
operator fun plus(weeks: LongWeeks): DateTime
operator fun plus(days: IntDays): DateTime
operator fun plus(days: LongDays): DateTime
operator fun plus(hours: IntHours): DateTime
operator fun plus(hours: LongHours): DateTime
operator fun plus(minutes: IntMinutes): DateTime
operator fun plus(minutes: LongMinutes): DateTime
operator fun plus(seconds: IntSeconds): DateTime
operator fun plus(seconds: LongSeconds): DateTime
operator fun plus(milliseconds: IntMilliseconds): DateTime
operator fun plus(milliseconds: LongMilliseconds): DateTime
operator fun plus(microseconds: IntMicroseconds): DateTime
operator fun plus(microseconds: LongMicroseconds): DateTime
operator fun plus(nanoseconds: IntNanoseconds): DateTime
operator fun plus(nanoseconds: LongNanoseconds): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

rangeTo

operator fun rangeTo(other: DateTime): DateTimeInterval
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

secondOfUnixEpochAt

The second of the Unix epoch.

fun secondOfUnixEpochAt(offset: UtcOffset): Long
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

secondsSinceUnixEpochAt

The number of seconds relative to the Unix epoch of 1970-01-01T00:00Z at a particular offset. This is a "floor" value, so 1 nanosecond before the Unix epoch will be at a distance of 1 second.

fun secondsSinceUnixEpochAt(offset: UtcOffset): LongSeconds

toString

Converts this date-time to a string in ISO-8601 extended format. For example, 2012-04-15T17:31:45.923452091 or 2020-02-13T02:30.

(iosArm64, iosX64, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86) fun toString(): <ERROR CLASS>
(jvm) fun toString(): String
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

unixEpochMillisecondAt

fun unixEpochMillisecondAt(offset: UtcOffset): Long
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

unixEpochSecondAt

fun unixEpochSecondAt(offset: UtcOffset): Long

Companion Object Properties

(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

MAX

The latest supported DateTime, which can be used as a "far future" sentinel.

val MAX: DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

MIN

The earliest supported DateTime, which can be used as a "far past" sentinel.

val MIN: DateTime

Companion Object Functions

(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

fromMillisecondOfUnixEpoch

Creates a DateTime from the millisecond of the Unix epoch at offset.

fun fromMillisecondOfUnixEpoch(millisecond: Long, offset: UtcOffset): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

fromMillisecondsSinceUnixEpoch

Creates a DateTime from a duration of milliseconds relative to the Unix epoch at offset.

fun fromMillisecondsSinceUnixEpoch(millisecondsSinceUnixEpoch: LongMilliseconds, offset: UtcOffset): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

fromSecondOfUnixEpoch

Creates a DateTime from the second of the Unix epoch at offset and optionally, the nanosecond of the second.

fun fromSecondOfUnixEpoch(second: Long, nanosecond: Int = 0, offset: UtcOffset): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

fromSecondsSinceUnixEpoch

Creates a DateTime from a duration of seconds relative to the Unix epoch at offset, optionally, with some number of additional nanoseconds added to it.

fun fromSecondsSinceUnixEpoch(secondsSinceUnixEpoch: LongSeconds, nanosecondAdjustment: IntNanoseconds = 0.nanoseconds, offset: UtcOffset): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

fromUnixEpochMillisecond

fun fromUnixEpochMillisecond(millisecond: Long, offset: UtcOffset): DateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

fromUnixEpochSecond

fun fromUnixEpochSecond(second: Long, nanosecondAdjustment: Int = 0, offset: UtcOffset): DateTime

Extension Functions

(jvm)

endOfWeek

The date-time at the last representable instant of the week that this date-time falls in. The first day of the week will be determined by locale.

fun DateTime.endOfWeek(locale: Locale): DateTime
(jvm)

startOfWeek

The date-time at the first instant of the week that this date-time falls in. The first day of the week will be determined by locale.

fun DateTime.startOfWeek(locale: Locale): DateTime
(jvm)

toJavaLocalDateTime

Convert to an equivalent Java LocalDateTime.

fun DateTime.toJavaLocalDateTime(): LocalDateTime
(jvm)

week

The interval defining the week that this date-time falls within. The first day of the week will be the default associated with the provided locale.

fun DateTime.week(locale: Locale): DateTimeInterval
(jvm)

weekBasedYear

The week-based year, calculated using the week definition associated with the provided locale. This value differs from the regular ISO year when the week number falls in the preceding or following year.

fun DateTime.weekBasedYear(locale: Locale): Int
(jvm)

weekInterval

fun DateTime.weekInterval(locale: Locale): DateTimeInterval
(jvm)

weekOfMonth

The week of the month, from 0-6, calculated using the default week definition associated with the provided locale.

fun DateTime.weekOfMonth(locale: Locale): Int
(jvm)

weekOfWeekBasedYear

The week number of the week-based year, calculated using the week definition associated with the provided locale.

fun DateTime.weekOfWeekBasedYear(locale: Locale): Int
(jvm)

weekOfYear

The week of the year, calculated using the week definition associated with the provided locale. If the week number is associated with the preceding year, 0 will be returned.

fun DateTime.weekOfYear(locale: Locale): Int