core / io.islandtime / OffsetDateTime

OffsetDateTime

(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86) class OffsetDateTime : TimePoint<OffsetDateTime>

A date and time of day with an offset from UTC.

OffsetDateTime is intended to be used primarily for use cases involving persistence or network transfer where the application of time zone rules may be undesirable. For most applications, ZonedDateTime is a better choice since it takes time zone rules into account when performing calendrical calculations.

Constructors

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

<init>

Create an OffsetDateTime.

<init>(date: Date, time: Time, offset: UtcOffset)
<init>(year: Int, month: Month, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int, offset: UtcOffset)
<init>(year: Int, monthNumber: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int, offset: UtcOffset)
<init>(year: Int, dayOfYear: Int, hour: Int, minute: Int, second: Int, nanosecond: Int, offset: UtcOffset)

Create an OffsetDateTime by combining a DateTime and UtcOffset.

<init>(dateTime: DateTime, offset: UtcOffset)

Properties

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

additionalNanosecondsSinceUnixEpoch

The number of additional nanoseconds on top of secondsSinceUnixEpoch.

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

date

The local date.

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

dateTime

The local date and time of day.

val dateTime: DateTime
(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 -- also known as the ordinal date in ISO-8601.

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)

instant

val instant: Instant
(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 this date's month in days.

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

lengthOfYear

The length of this date's year in days.

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

millisecondsSinceUnixEpoch

The number of milliseconds since the Unix epoch of 1970-01-01T00:00Z.

val millisecondsSinceUnixEpoch: LongMilliseconds
(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)

nanosecond

The nanosecond of the second.

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

offset

The offset from UTC.

val offset: UtcOffset
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

offsetTime

val offsetTime: OffsetTime
(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)

secondsSinceUnixEpoch

The number of seconds since the Unix epoch of 1970-01-01T00:00Z.

val secondsSinceUnixEpoch: LongSeconds
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

time

The local time of day.

val time: Time
(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)

adjustedTo

Change the offset of an OffsetDateTime, adjusting the date and time components such that the instant represented by it remains the same

fun adjustedTo(newOffset: UtcOffset): OffsetDateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

copy

Return a new OffsetDateTime, replacing any of the components with new values.

fun copy(dateTime: DateTime = this.dateTime, offset: UtcOffset = this.offset): OffsetDateTime
fun copy(date: Date = this.date, time: Time = this.time, offset: UtcOffset = this.offset): OffsetDateTime
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, offset: UtcOffset = this.offset): OffsetDateTime
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, offset: UtcOffset = this.offset): OffsetDateTime
(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)

minus

Return an OffsetDateTime with period subtracted from it.

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

plus

Return an OffsetDateTime with period added to it.

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

rangeTo

operator fun rangeTo(other: OffsetDateTime): OffsetDateTimeInterval

toString

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

Companion Object Properties

DEFAULT_SORT_ORDER

Compare by instant, then date-time. Using this Comparator guarantees a deterministic order when sorting.

(iosArm64, iosX64, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86) val DEFAULT_SORT_ORDER: <ERROR CLASS>
(jvm) val DEFAULT_SORT_ORDER: Comparator<OffsetDateTime>
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

MAX

The largest supported OffsetDateTime, which can be used as a "far future" sentinel.

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

MIN

The smallest supported OffsetDateTime, which can be used as a "far past" sentinel.

val MIN: OffsetDateTime

TIMELINE_ORDER

Compare by timeline order only, ignoring any offset differences.

(iosArm64, iosX64, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86) val TIMELINE_ORDER: <ERROR CLASS>
(jvm) val TIMELINE_ORDER: Comparator<TimePoint<*>>

Companion Object Functions

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

fromMillisecondOfUnixEpoch

Create an OffsetDateTime from the millisecond of the Unix epoch at offset.

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

fromMillisecondsSinceUnixEpoch

Create an OffsetDateTime from a duration of milliseconds relative to the Unix epoch at offset.

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

fromSecondOfUnixEpoch

Create an OffsetDateTime 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): OffsetDateTime
(iosArm64, iosX64, jvm, macosX64, tvosArm64, tvosX64, watchosArm64, watchosX86)

fromSecondsSinceUnixEpoch

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

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

fromUnixEpochMillisecond

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

fromUnixEpochSecond

fun fromUnixEpochSecond(second: Long, nanoOfSecond: Int, offset: UtcOffset): OffsetDateTime

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 OffsetDateTime.endOfWeek(locale: Locale): OffsetDateTime
(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 OffsetDateTime.startOfWeek(locale: Locale): OffsetDateTime
(jvm)

toJavaOffsetDateTime

Convert to an equivalent Java OffsetDateTime.

fun OffsetDateTime.toJavaOffsetDateTime(): OffsetDateTime
(jvm)

weekInterval

The interval of the week that this date falls within. The first day of the week will be determined by locale. The offset will be preserved in both the start and end date-times.

fun OffsetDateTime.weekInterval(locale: Locale): OffsetDateTimeInterval