DateTime

class DateTime(date: Date, time: Time) : Comparable<DateTime>

A date and time of day in an ambiguous region.

Parameters

date

the date

time

the time

Constructors

DateTime
Link copied to clipboard
common
fun DateTime(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0)
Creates a DateTime.
DateTime
Link copied to clipboard
common
fun DateTime(year: Int, monthNumber: Int, day: Int, hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0)
Creates a DateTime.
DateTime
Link copied to clipboard
common
fun DateTime(year: Int, dayOfYear: Int, hour: Int, minute: Int, second: Int, nanosecond: Int)
Creates a DateTime.
DateTime
Link copied to clipboard
common
fun DateTime(date: Date, time: Time)
Creates a DateTime by combining a Date and Time.

Types

Companion
Link copied to clipboard
common
object Companion

Functions

compareTo
Link copied to clipboard
common
open operator override fun compareTo(other: DateTime): Int
component1
Link copied to clipboard
common
operator fun component1(): Date
component2
Link copied to clipboard
common
operator fun component2(): Time
copy
Link copied to clipboard
common
fun copy(date: Date = this.date, time: Time = this.time): DateTime
Returns a copy of this date-time with the values of any individual components replaced by the new values specified.
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
Returns a copy of this date-time with the values of any individual components replaced by the new values specified.
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
Returns a copy of this date-time with the values of any individual components replaced by the new values specified.
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
Returns a copy of this date-time with the values of any individual components replaced by the new values specified.
equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
millisecondOfUnixEpochAt
Link copied to clipboard
common
fun millisecondOfUnixEpochAt(offset: UtcOffset): Long
The millisecond of the Unix epoch.
millisecondsSinceUnixEpochAt
Link copied to clipboard
common
fun millisecondsSinceUnixEpochAt(offset: UtcOffset): LongMilliseconds
The number of milliseconds relative to the Unix epoch of 1970-01-01T00:00Z at a particular offset.
minus
Link copied to clipboard
common
operator fun minus(duration: Duration): DateTime
operator fun minus(days: IntDays): DateTime
operator fun minus(hours: IntHours): DateTime
operator fun minus(microseconds: IntMicroseconds): DateTime
operator fun minus(milliseconds: IntMilliseconds): DateTime
operator fun minus(minutes: IntMinutes): DateTime
operator fun minus(months: IntMonths): DateTime
operator fun minus(nanoseconds: IntNanoseconds): DateTime
operator fun minus(seconds: IntSeconds): DateTime
operator fun minus(weeks: IntWeeks): DateTime
operator fun minus(years: IntYears): DateTime
operator fun minus(days: LongDays): DateTime
operator fun minus(hours: LongHours): DateTime
operator fun minus(microseconds: LongMicroseconds): DateTime
operator fun minus(milliseconds: LongMilliseconds): DateTime
operator fun minus(minutes: LongMinutes): DateTime
operator fun minus(months: LongMonths): DateTime
operator fun minus(nanoseconds: LongNanoseconds): DateTime
operator fun minus(seconds: LongSeconds): DateTime
operator fun minus(weeks: LongWeeks): DateTime
operator fun minus(years: LongYears): DateTime
operator fun minus(period: Period): DateTime
Returns this date-time with period subtracted from it.
plus
Link copied to clipboard
common
operator fun plus(duration: Duration): DateTime
operator fun plus(days: IntDays): DateTime
operator fun plus(hours: IntHours): DateTime
operator fun plus(microseconds: IntMicroseconds): DateTime
operator fun plus(milliseconds: IntMilliseconds): DateTime
operator fun plus(minutes: IntMinutes): DateTime
operator fun plus(months: IntMonths): DateTime
operator fun plus(nanoseconds: IntNanoseconds): DateTime
operator fun plus(seconds: IntSeconds): DateTime
operator fun plus(weeks: IntWeeks): DateTime
operator fun plus(years: IntYears): DateTime
operator fun plus(days: LongDays): DateTime
operator fun plus(hours: LongHours): DateTime
operator fun plus(microseconds: LongMicroseconds): DateTime
operator fun plus(milliseconds: LongMilliseconds): DateTime
operator fun plus(minutes: LongMinutes): DateTime
operator fun plus(months: LongMonths): DateTime
operator fun plus(nanoseconds: LongNanoseconds): DateTime
operator fun plus(seconds: LongSeconds): DateTime
operator fun plus(weeks: LongWeeks): DateTime
operator fun plus(years: LongYears): DateTime
operator fun plus(period: Period): DateTime
Returns this date-time with period added to it.
rangeTo
Link copied to clipboard
common
operator fun rangeTo(other: DateTime): DateTimeInterval
secondOfUnixEpochAt
Link copied to clipboard
common
fun secondOfUnixEpochAt(offset: UtcOffset): Long
The second of the Unix epoch.
secondsSinceUnixEpochAt
Link copied to clipboard
common
fun secondsSinceUnixEpochAt(offset: UtcOffset): LongSeconds
The number of seconds relative to the Unix epoch of 1970-01-01T00:00Z at a particular offset.
toString
Link copied to clipboard
common
open override fun toString(): String
Converts this date-time to a string in ISO-8601 extended format.

Properties

additionalNanosecondsSinceUnixEpoch
Link copied to clipboard
common
val additionalNanosecondsSinceUnixEpoch: IntNanoseconds
The number of additional nanoseconds that should be applied on top of the number of seconds since the Unix epoch returned by secondsSinceUnixEpochAt.
date
Link copied to clipboard
common
val date: Date
The date.
dayOfMonth
Link copied to clipboard
common
val dayOfMonth: Int
The day of the month.
dayOfWeek
Link copied to clipboard
common
val dayOfWeek: DayOfWeek
The day of the week.
dayOfYear
Link copied to clipboard
common
val dayOfYear: Int
The day of the year.
hour
Link copied to clipboard
common
val hour: Int
The hour of the day.
minute
Link copied to clipboard
common
val minute: Int
The minute of the hour.
month
Link copied to clipboard
common
val month: Month
The month of the year.
monthNumber
Link copied to clipboard
common
val monthNumber: Int
The ISO month number, from 1-12.
nanosecond
Link copied to clipboard
common
val nanosecond: Int
The nanosecond of the second.
second
Link copied to clipboard
common
val second: Int
The second of the minute.
time
Link copied to clipboard
common
val time: Time
The time of day.
year
Link copied to clipboard
common
val year: Int
The year.

Extensions

at
Link copied to clipboard
common
infix fun DateTime.at(offset: UtcOffset): OffsetDateTime
Combines a local date and time with a UTC offset to create an OffsetDateTime.
infix fun DateTime.at(zone: TimeZone): ZonedDateTime
Combines a local date and time with a time zone to create a ZonedDateTime.
endOfMonth
Link copied to clipboard
common
val DateTime.endOfMonth: DateTime
The date-time at the last representable instant of the month that this date-time falls in.
endOfWeek
Link copied to clipboard
common
val DateTime.endOfWeek: DateTime
The date-time at the last representable instant of the ISO week that this date-time falls in.
fun DateTime.endOfWeek(settings: WeekSettings): DateTime
The date-time at the last representable instant of the week that this date-time falls in.
fun DateTime.endOfWeek(locale: Locale): DateTime
The date-time at the last representable instant of the week that this date-time falls in.
endOfYear
Link copied to clipboard
common
val DateTime.endOfYear: DateTime
The date-time at the last representable instant of the year that this date-time falls in.
isInLeapDay
Link copied to clipboard
common
val DateTime.isInLeapDay: Boolean
Checks if this date-time falls within February 29.
isInLeapYear
Link copied to clipboard
common
val DateTime.isInLeapYear: Boolean
Checks if this date-time falls within a leap year.
lengthOfMonth
Link copied to clipboard
common
val DateTime.lengthOfMonth: IntDays
The length of this date-time's month in days.
lengthOfWeekBasedYear
Link copied to clipboard
common
val DateTime.lengthOfWeekBasedYear: IntWeeks
The length of the ISO week-based year that this date-time falls in, either 52 or 53 weeks.
lengthOfYear
Link copied to clipboard
common
val DateTime.lengthOfYear: IntDays
The length of this date-time's year in days.
next
Link copied to clipboard
common
fun DateTime.next(dayOfWeek: DayOfWeek): DateTime
The next date-time after this one that falls on dayOfWeek.
nextOrSame
Link copied to clipboard
common
fun DateTime.nextOrSame(dayOfWeek: DayOfWeek): DateTime
The next date-time that falls on dayOfWeek, or this date-time if it falls on the same day.
previous
Link copied to clipboard
common
fun DateTime.previous(dayOfWeek: DayOfWeek): DateTime
The last date-time before this one that falls on dayOfWeek.
previousOrSame
Link copied to clipboard
common
fun DateTime.previousOrSame(dayOfWeek: DayOfWeek): DateTime
The previous date-time that falls on dayOfWeek, or this date-time if it falls on the same day.
roundedDownTo
Link copied to clipboard
common
fun DateTime.roundedDownTo(unit: TimeUnit): DateTime
Returns this date-time, rounded down to match the precision of a given unit.
roundedDownToNearest
Link copied to clipboard
common
fun DateTime.roundedDownToNearest(increment: IntHours): DateTime
Returns this date-time, rounded down to the nearest hour that satisfies the increment.
fun DateTime.roundedDownToNearest(increment: IntMinutes): DateTime
Returns this date-time, rounded down to the nearest minute that satisfies the increment.
fun DateTime.roundedDownToNearest(increment: IntSeconds): DateTime
Returns this date-time, rounded down to the nearest second that satisfies the increment.
fun DateTime.roundedDownToNearest(increment: IntMilliseconds): DateTime
Returns this date-time, rounded down to the nearest millisecond that satisfies the increment.
fun DateTime.roundedDownToNearest(increment: IntMicroseconds): DateTime
Returns this date-time, rounded down to the nearest microsecond that satisfies the increment.
fun DateTime.roundedDownToNearest(increment: IntNanoseconds): DateTime
Returns this date-time, rounded down to the nearest nanosecond that satisfies the increment.
roundedTo
Link copied to clipboard
common
fun DateTime.roundedTo(unit: TimeUnit): DateTime
Returns this date-time, rounded to match the precision of a given unit.
roundedToNearest
Link copied to clipboard
common
fun DateTime.roundedToNearest(increment: IntHours): DateTime
Returns this date-time, rounded to the nearest hour that satisfies the increment.
fun DateTime.roundedToNearest(increment: IntMinutes): DateTime
Returns this date-time, rounded to the nearest minute that satisfies the increment.
fun DateTime.roundedToNearest(increment: IntSeconds): DateTime
Returns this date-time, rounded to the nearest second that satisfies the increment.
fun DateTime.roundedToNearest(increment: IntMilliseconds): DateTime
Returns this date-time, rounded to the nearest millisecond that satisfies the increment.
fun DateTime.roundedToNearest(increment: IntMicroseconds): DateTime
Returns this date-time, rounded to the nearest microsecond that satisfies the increment.
fun DateTime.roundedToNearest(increment: IntNanoseconds): DateTime
Returns this date-time, rounded to the nearest nanosecond that satisfies the increment.
roundedUpTo
Link copied to clipboard
common
fun DateTime.roundedUpTo(unit: TimeUnit): DateTime
Returns this date-time, rounded up to match the precision of a given unit.
roundedUpToNearest
Link copied to clipboard
common
fun DateTime.roundedUpToNearest(increment: IntHours): DateTime
Returns this date-time, rounded up to the nearest hour that satisfies the increment.
fun DateTime.roundedUpToNearest(increment: IntMinutes): DateTime
Returns this date-time, rounded up to the nearest minute that satisfies the increment.
fun DateTime.roundedUpToNearest(increment: IntSeconds): DateTime
Returns this date-time, rounded up to the nearest second that satisfies the increment.
fun DateTime.roundedUpToNearest(increment: IntMilliseconds): DateTime
Returns this date-time, rounded up to the nearest millisecond that satisfies the increment.
fun DateTime.roundedUpToNearest(increment: IntMicroseconds): DateTime
Returns this date-time, rounded up to the nearest microsecond that satisfies the increment.
fun DateTime.roundedUpToNearest(increment: IntNanoseconds): DateTime
Returns this date-time, rounded up to the nearest nanosecond that satisfies the increment.
startOfMonth
Link copied to clipboard
common
val DateTime.startOfMonth: DateTime
The date-time at the first instant of the month that this date-time falls in.
startOfWeek
Link copied to clipboard
common
val DateTime.startOfWeek: DateTime
The date-time at the first instant of the ISO week that this date-time falls in.
fun DateTime.startOfWeek(settings: WeekSettings): DateTime
The date-time at the first instant of the week that this date-time falls in.
fun DateTime.startOfWeek(locale: Locale): DateTime
The date-time at the first instant of the week that this date-time falls in.
startOfYear
Link copied to clipboard
common
val DateTime.startOfYear: DateTime
The date-time at the first instant of the year that this date-time falls in.
toInstantAt
Link copied to clipboard
common
fun DateTime.toInstantAt(offset: UtcOffset): Instant
Converts this date-time to the corresponding Instant at offset.
toJavaLocalDateTime
Link copied to clipboard
fun DateTime.toJavaLocalDateTime(): LocalDateTime
Converts this date-time to an equivalent Java LocalDateTime.
toNSDateComponents
Link copied to clipboard
darwin
fun DateTime.toNSDateComponents(includeCalendar: Boolean = false): <ERROR CLASS>
Converts this date-time to an equivalent NSDateComponents object.
toYear
Link copied to clipboard
common
fun DateTime.toYear(): Year
Returns this date-time with the precision reduced to the year.
toYearMonth
Link copied to clipboard
common
fun DateTime.toYearMonth(): YearMonth
Returns this date-time with the precision reduced to the month.
truncatedTo
Link copied to clipboard
common
fun DateTime.truncatedTo(unit: TimeUnit): DateTime
Returns this date-time, rounded down to match the precision of a given unit.
until
Link copied to clipboard
common
infix fun DateTime.until(to: DateTime): DateTimeInterval
Creates a DateTimeInterval from this date-time up to, but not including the nanosecond represented by to.
week
Link copied to clipboard
common
val DateTime.week: DateTimeInterval
The interval defining the ISO week that this date-time falls within.
fun DateTime.week(settings: WeekSettings): DateTimeInterval
The interval defining the week that this date-time falls within.
fun DateTime.week(locale: Locale): DateTimeInterval
The interval defining the week that this date-time falls within.
weekBasedYear
Link copied to clipboard
common
val DateTime.weekBasedYear: Int
The week-based year used in the ISO week date system.
fun DateTime.weekBasedYear(settings: WeekSettings): Int
The week-based year, calculated using the week definition in settings.
fun DateTime.weekBasedYear(locale: Locale): Int
The week-based year, calculated using the week definition associated with the provided locale.
weekOfMonth
Link copied to clipboard
common
val DateTime.weekOfMonth: Int
The week of the month, from 0-6, calculated using the ISO week definition.
fun DateTime.weekOfMonth(settings: WeekSettings): Int
The week of the month, from 0-6, calculated using the week definition in settings.
fun DateTime.weekOfMonth(locale: Locale): Int
The week of the month, from 0-6, calculated using the default week definition associated with the provided locale.
weekOfWeekBasedYear
Link copied to clipboard
common
val DateTime.weekOfWeekBasedYear: Int
The week number used in the ISO week date system.
fun DateTime.weekOfWeekBasedYear(settings: WeekSettings): Int
The week number of the week-based year, calculated using the week definition in settings.
fun DateTime.weekOfWeekBasedYear(locale: Locale): Int
The week number of the week-based year, calculated using the week definition associated with the provided locale.
weekOfYear
Link copied to clipboard
common
val DateTime.weekOfYear: Int
The week of the year, calculated using the ISO week definition.
fun DateTime.weekOfYear(settings: WeekSettings): Int
The week of the year, calculated using the week definition in settings.
fun DateTime.weekOfYear(locale: Locale): Int
The week of the year, calculated using the week definition associated with the provided locale.