DateTime¶
@Serializable(with = DateTimeIsoSerializer::class)
class DateTime(val date: Date, val time: Time) : Comparable<DateTime>
A date and time of day in an ambiguous region.
Parameters¶
common
| date | the date |
| time | the time |
Constructors¶
| DateTime | common constructor(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0)Creates a DateTime. constructor(year: Int, monthNumber: Int, day: Int, hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0)Creates a DateTime. constructor(year: Int, dayOfYear: Int, hour: Int, minute: Int, second: Int, nanosecond: Int)Creates a DateTime. constructor(date: Date, time: Time)Creates a DateTime by combining a Date and Time. |
Types¶
| Name | Summary |
|---|---|
| Companion | common object Companion |
Properties¶
| Name | Summary |
|---|---|
| additionalNanosecondsSinceUnixEpoch | common val additionalNanosecondsSinceUnixEpoch: NanosecondsThe number of additional nanoseconds that should be applied on top of the number of seconds since the Unix epoch returned by secondsSinceUnixEpochAt. |
| date | common val date: DateThe date. |
| dayOfMonth | common val dayOfMonth: IntThe day of the month. |
| dayOfWeek | common val dayOfWeek: DayOfWeekThe day of the week. |
| dayOfYear | common val dayOfYear: IntThe day of the year. |
| endOfMonth | common val DateTime.endOfMonth: DateTimeThe date-time at the last representable instant of the month that this date-time falls in. |
| endOfWeek | common val DateTime.endOfWeek: DateTimeThe date-time at the last representable instant of the ISO week that this date-time falls in. |
| endOfYear | common val DateTime.endOfYear: DateTimeThe date-time at the last representable instant of the year that this date-time falls in. |
| hour | common val hour: IntThe hour of the day. |
| isInLeapDay | common val DateTime.isInLeapDay: BooleanChecks if this date-time falls within February 29. |
| isInLeapYear | common val DateTime.isInLeapYear: BooleanChecks if this date-time falls within a leap year. |
| lengthOfMonth | common val DateTime.lengthOfMonth: DaysThe length of this date-time's month in days. |
| lengthOfWeekBasedYear | common val DateTime.lengthOfWeekBasedYear: WeeksThe length of the ISO week-based year that this date-time falls in, either 52 or 53 weeks. |
| lengthOfYear | common val DateTime.lengthOfYear: DaysThe length of this date-time's year in days. |
| minute | common val minute: IntThe minute of the hour. |
| month | common val month: MonthThe month of the year. |
| monthNumber | common val monthNumber: IntThe ISO month number, from 1-12. |
| nanosecond | common val nanosecond: IntThe nanosecond of the second. |
| second | common val second: IntThe second of the minute. |
| startOfMonth | common val DateTime.startOfMonth: DateTimeThe date-time at the first instant of the month that this date-time falls in. |
| startOfWeek | common val DateTime.startOfWeek: DateTimeThe date-time at the first instant of the ISO week that this date-time falls in. |
| startOfYear | common val DateTime.startOfYear: DateTimeThe date-time at the first instant of the year that this date-time falls in. |
| time | common val time: TimeThe time of day. |
| week | common val DateTime.week: DateTimeIntervalThe interval defining the ISO week that this date-time falls within. |
| weekBasedYear | common val DateTime.weekBasedYear: IntThe week-based year used in the ISO week date system. This value differs from the regular ISO year when the week number falls in the preceding or following year. |
| weekOfMonth | common val DateTime.weekOfMonth: IntThe week of the month, from 0-6, calculated using the ISO week definition. |
| weekOfWeekBasedYear | common val DateTime.weekOfWeekBasedYear: IntThe week number used in the ISO week date system. |
| weekOfYear | common val DateTime.weekOfYear: IntThe week of the year, calculated using the ISO week definition. If the week number is associated with the preceding year, 0 will be returned. |
| year | common val year: IntThe year. |
Functions¶
| Name | Summary |
|---|---|
| at | common infix fun DateTime.at(zone: TimeZone): ZonedDateTimeCombines a local date and time with a time zone to create a ZonedDateTime. common infix fun DateTime.at(offset: UtcOffset): OffsetDateTimeCombines a local date and time with a UTC offset to create an OffsetDateTime. |
| compareTo | common open operator override fun compareTo(other: DateTime): Int |
| component1 | common operator fun component1(): Date |
| component2 | common operator fun component2(): Time |
| copy | common fun copy(date: Date = this.date, time: Time = this.time): DateTimefun copy(year: Int = this.year, dayOfYear: Int, hour: Int = this.hour, minute: Int = this.minute, second: Int = this.second, nanosecond: Int = this.nanosecond): DateTimefun 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): DateTimefun 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): DateTimeReturns a copy of this date-time with the values of any individual components replaced by the new values specified. |
| endOfWeek | common fun DateTime.endOfWeek(settings: WeekSettings): DateTimeThe 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 the system settings. This may differ from the first day of the week associated with the default locale on platforms that allow this to be customized. common fun DateTime.endOfWeek(locale: Locale): DateTimeThe 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. |
| equals | common open operator override fun equals(other: Any?): Boolean |
| hashCode | common open override fun hashCode(): Int |
| millisecondOfUnixEpochAt | common fun millisecondOfUnixEpochAt(offset: UtcOffset): LongThe millisecond of the Unix epoch. |
| millisecondsSinceUnixEpochAt | common fun millisecondsSinceUnixEpochAt(offset: UtcOffset): MillisecondsThe 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. |
| minus | common operator fun minus(centuries: Centuries): DateTimeReturns this date-time with centuries subtracted from it. common operator fun minus(days: Days): DateTimeReturns this date-time with days subtracted from it. common operator fun minus(decades: Decades): DateTimeReturns this date-time with decades subtracted from it. common operator fun minus(duration: Duration): DateTimecommon operator fun minus(hours: Hours): DateTimeReturns this date-time with hours subtracted from it. common operator fun minus(microseconds: Microseconds): DateTimeReturns this date-time with microseconds subtracted from it. common operator fun minus(milliseconds: Milliseconds): DateTimeReturns this date-time with milliseconds subtracted from it. common operator fun minus(minutes: Minutes): DateTimeReturns this date-time with minutes subtracted from it. common operator fun minus(months: Months): DateTimeReturns this date-time with months subtracted from it. common operator fun minus(nanoseconds: Nanoseconds): DateTimeReturns this date-time with nanoseconds subtracted from it. common operator fun minus(period: Period): DateTimeReturns this date-time with period subtracted from it. common operator fun minus(seconds: Seconds): DateTimeReturns this date-time with seconds subtracted from it. common operator fun minus(weeks: Weeks): DateTimeReturns this date-time with weeks subtracted from it. common operator fun minus(years: Years): DateTimeReturns this date-time with years subtracted from it. common operator fun minus(duration: Duration): DateTimeReturns this date-time with duration subtracted from it. |
| next | common fun DateTime.next(dayOfWeek: DayOfWeek): DateTimeThe next date-time after this one that falls on dayOfWeek. |
| nextOrSame | common fun DateTime.nextOrSame(dayOfWeek: DayOfWeek): DateTimeThe next date-time that falls on dayOfWeek, or this date-time if it falls on the same day. |
| plus | common operator fun plus(centuries: Centuries): DateTimeReturns this date-tme with centuries added to it. common operator fun plus(days: Days): DateTimeReturns this date-time with days added to it. common operator fun plus(decades: Decades): DateTimeReturns this date-time with decades added to it. common operator fun plus(duration: Duration): DateTimecommon operator fun plus(hours: Hours): DateTimeReturns this date-time with hours added to it. common operator fun plus(microseconds: Microseconds): DateTimeReturns this date-time with microseconds added to it. common operator fun plus(milliseconds: Milliseconds): DateTimeReturns this date-time with milliseconds added to it. common operator fun plus(minutes: Minutes): DateTimeReturns this date-time with minutes added to it. common operator fun plus(months: Months): DateTimeReturns this date-time with months added to it. common operator fun plus(nanoseconds: Nanoseconds): DateTimeReturns this date-time with nanoseconds added to it. common operator fun plus(period: Period): DateTimeReturns this date-time with period added to it. common operator fun plus(seconds: Seconds): DateTimeReturns this date-time with seconds added to it. common operator fun plus(weeks: Weeks): DateTimeReturns this date-time with weeks added to it. common operator fun plus(years: Years): DateTimeReturns this date-time with years added to it. common operator fun plus(duration: Duration): DateTimeReturns this date-time with duration added to it. |
| previous | common fun DateTime.previous(dayOfWeek: DayOfWeek): DateTimeThe last date-time before this one that falls on dayOfWeek. |
| previousOrSame | common fun DateTime.previousOrSame(dayOfWeek: DayOfWeek): DateTimeThe previous date-time that falls on dayOfWeek, or this date-time if it falls on the same day. |
| rangeTo | common operator fun rangeTo(other: DateTime): DateTimeInterval |
| roundedDownTo | common fun DateTime.roundedDownTo(unit: TimeUnit): DateTimeReturns this date-time, rounded down to match the precision of a given unit. |
| roundedDownToNearest | common fun DateTime.roundedDownToNearest(increment: Hours): DateTimeReturns this date-time, rounded down to the nearest hour that satisfies the increment. common fun DateTime.roundedDownToNearest(increment: Microseconds): DateTimeReturns this date-time, rounded down to the nearest microsecond that satisfies the increment. common fun DateTime.roundedDownToNearest(increment: Milliseconds): DateTimeReturns this date-time, rounded down to the nearest millisecond that satisfies the increment. common fun DateTime.roundedDownToNearest(increment: Minutes): DateTimeReturns this date-time, rounded down to the nearest minute that satisfies the increment. common fun DateTime.roundedDownToNearest(increment: Nanoseconds): DateTimeReturns this date-time, rounded down to the nearest nanosecond that satisfies the increment. common fun DateTime.roundedDownToNearest(increment: Seconds): DateTimeReturns this date-time, rounded down to the nearest second that satisfies the increment. |
| roundedTo | common fun DateTime.roundedTo(unit: TimeUnit): DateTimeReturns this date-time, rounded to match the precision of a given unit. If the time is halfway between whole values of the unit, it will be rounded up. |
| roundedToNearest | common fun DateTime.roundedToNearest(increment: Hours): DateTimeReturns this date-time, rounded to the nearest hour that satisfies the increment. If the time is halfway between increments, it will be rounded up. common fun DateTime.roundedToNearest(increment: Microseconds): DateTimeReturns this date-time, rounded to the nearest microsecond that satisfies the increment. If the time is halfway between increments, it will be rounded up. common fun DateTime.roundedToNearest(increment: Milliseconds): DateTimeReturns this date-time, rounded to the nearest millisecond that satisfies the increment. If the time is halfway between increments, it will be rounded up. common fun DateTime.roundedToNearest(increment: Minutes): DateTimeReturns this date-time, rounded to the nearest minute that satisfies the increment. If the time is halfway between increments, it will be rounded up. common fun DateTime.roundedToNearest(increment: Nanoseconds): DateTimeReturns this date-time, rounded to the nearest nanosecond that satisfies the increment. If the time is halfway between increments, it will be rounded up. common fun DateTime.roundedToNearest(increment: Seconds): DateTimeReturns this date-time, rounded to the nearest second that satisfies the increment. If the time is halfway between increments, it will be rounded up. |
| roundedUpTo | common fun DateTime.roundedUpTo(unit: TimeUnit): DateTimeReturns this date-time, rounded up to match the precision of a given unit. |
| roundedUpToNearest | common fun DateTime.roundedUpToNearest(increment: Hours): DateTimeReturns this date-time, rounded up to the nearest hour that satisfies the increment. common fun DateTime.roundedUpToNearest(increment: Microseconds): DateTimeReturns this date-time, rounded up to the nearest microsecond that satisfies the increment. common fun DateTime.roundedUpToNearest(increment: Milliseconds): DateTimeReturns this date-time, rounded up to the nearest millisecond that satisfies the increment. common fun DateTime.roundedUpToNearest(increment: Minutes): DateTimeReturns this date-time, rounded up to the nearest minute that satisfies the increment. common fun DateTime.roundedUpToNearest(increment: Nanoseconds): DateTimeReturns this date-time, rounded up to the nearest nanosecond that satisfies the increment. common fun DateTime.roundedUpToNearest(increment: Seconds): DateTimeReturns this date-time, rounded up to the nearest second that satisfies the increment. |
| secondOfUnixEpochAt | common fun secondOfUnixEpochAt(offset: UtcOffset): LongThe second of the Unix epoch. |
| secondsSinceUnixEpochAt | common fun secondsSinceUnixEpochAt(offset: UtcOffset): SecondsThe 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. |
| startOfWeek | common fun DateTime.startOfWeek(settings: WeekSettings): DateTimeThe 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 the system settings. This may differ from the first day of the week associated with the default locale on platforms that allow this to be customized. common fun DateTime.startOfWeek(locale: Locale): DateTimeThe 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. |
| toInstantAt | common fun DateTime.toInstantAt(offset: UtcOffset): InstantConverts this date-time to the corresponding Instant at offset. |
| toJavaLocalDateTime | jvm fun DateTime.toJavaLocalDateTime(): LocalDateTimeConverts this date-time to an equivalent Java LocalDateTime. |
| toNSDateComponents | darwin fun DateTime.toNSDateComponents(includeCalendar: Boolean = false): <Error class: unknown class>Converts this date-time to an equivalent NSDateComponents object. |
| toString | common open override fun toString(): StringConverts this date-time to a string in ISO-8601 extended format. For example, 2012-04-15T17:31:45.923452091 or 2020-02-13T02:30. |
| toYear | common fun DateTime.toYear(): YearReturns this date-time with the precision reduced to the year. |
| toYearMonth | common fun DateTime.toYearMonth(): YearMonthReturns this date-time with the precision reduced to the month. |
| truncatedTo | common fun DateTime.truncatedTo(unit: TimeUnit): DateTimeReturns this date-time, rounded down to match the precision of a given unit. |
| until | common infix fun DateTime.until(to: DateTime): DateTimeIntervalCreates a DateTimeInterval from this date-time up to, but not including the nanosecond represented by to. |
| week | common fun DateTime.week(settings: WeekSettings): DateTimeIntervalThe interval defining the week that this date-time falls within. The first day of the week will be determined by the provided settings. common fun DateTime.week(locale: Locale): DateTimeIntervalThe 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. |
| weekBasedYear | common fun DateTime.weekBasedYear(settings: WeekSettings): IntThe week-based year, calculated using the week definition in settings. This value differs from the regular ISO year when the week number falls in the preceding or following year. common fun DateTime.weekBasedYear(locale: Locale): IntThe 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. |
| weekOfMonth | common fun DateTime.weekOfMonth(settings: WeekSettings): IntThe week of the month, from 0-6, calculated using the week definition in settings. common fun DateTime.weekOfMonth(locale: Locale): IntThe week of the month, from 0-6, calculated using the default week definition associated with the provided locale. |
| weekOfWeekBasedYear | common fun DateTime.weekOfWeekBasedYear(settings: WeekSettings): IntThe week number of the week-based year, calculated using the week definition in settings. common fun DateTime.weekOfWeekBasedYear(locale: Locale): IntThe week number of the week-based year, calculated using the week definition associated with the provided locale. |
| weekOfYear | common fun DateTime.weekOfYear(settings: WeekSettings): IntThe week of the year, calculated using the week definition in settings. If the week number is associated with the preceding year, 0 will be returned.common fun DateTime.weekOfYear(locale: Locale): IntThe 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. |