Date

class Date(year: Int, month: Month, day: Int) : Comparable<Date>

A date in an ambiguous region.

Parameters

year

the year

month

the month

day

the day of the month

Throws

if the year or day is invalid

Constructors

Date
Link copied to clipboard
common
fun Date(year: Int, monthNumber: Int, day: Int)

Creates a Date from a year, ISO month number, and day of month.

Date
Link copied to clipboard
common
fun Date(year: Int, month: Month, day: Int)

Creates a Date from a year, month, and day of month.

Types

Companion
Link copied to clipboard
common
object Companion

Functions

compareTo
Link copied to clipboard
common
open operator override fun compareTo(other: Date): Int
component1
Link copied to clipboard
common
operator fun component1(): Int
component2
Link copied to clipboard
common
operator fun component2(): Month
component3
Link copied to clipboard
common
operator fun component3(): Int
copy
Link copied to clipboard
common
fun copy(year: Int = this.year, dayOfYear: Int = this.dayOfYear): Date
fun copy(year: Int = this.year, month: Month = this.month, dayOfMonth: Int = this.day): Date
fun copy(year: Int = this.year, monthNumber: Int, dayOfMonth: Int = this.day): Date

Returns a copy of this date 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
minus
Link copied to clipboard
common
operator fun minus(centuries: Centuries): Date

Returns this date with centuries subtracted from it.

operator fun minus(days: Days): Date

Returns this date with days subtracted from it.

operator fun minus(decades: Decades): Date

Returns this date with decades subtracted from it.

operator fun minus(months: Months): Date

Returns this date with months subtracted from it.

operator fun minus(period: Period): Date

Returns this date with period subtracted from it.

operator fun minus(weeks: Weeks): Date

Returns this date with weeks subtracted from it.

operator fun minus(years: Years): Date

Returns this date with years subtracted from it.

plus
Link copied to clipboard
common
operator fun plus(centuries: Centuries): Date

Returns this date with centuries added to it.

operator fun plus(days: Days): Date

Returns this date with days added to it.

operator fun plus(decades: Decades): Date

Returns this date with decades added to it.

operator fun plus(months: Months): Date

Returns this date with months added to it.

operator fun plus(period: Period): Date

Returns this date with period added to it.

operator fun plus(weeks: Weeks): Date

Returns this date with weeks added to it.

operator fun plus(years: Years): Date

Returns this date with years added to it.

rangeTo
Link copied to clipboard
common
operator fun rangeTo(other: Date): DateRange
toString
Link copied to clipboard
common
open override fun toString(): String

Converts this date to a string in ISO-8601 extended format using the "calendar date" form. For example, 2012-04-15.

Properties

dayOfMonth
Link copied to clipboard
common
val dayOfMonth: Int

The day of the month.

dayOfUnixEpoch
Link copied to clipboard
common
val dayOfUnixEpoch: Long

The day of the Unix epoch.

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.

daysSinceUnixEpoch
Link copied to clipboard
common
val daysSinceUnixEpoch: Days

The number of days away from the Unix epoch (1970-01-01T00:00Z) that this date falls.

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.

year
Link copied to clipboard
common
val year: Int

The year.

Extensions

at
Link copied to clipboard
common
infix fun Date.at(time: Time): DateTime

Combines a Date with a Time to create a DateTime.

infix fun Date.at(offsetTime: OffsetTime): OffsetDateTime

Combines a local date with a time and UTC offset to create an OffsetDateTime.

atTime
Link copied to clipboard
common
fun Date.atTime(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): DateTime

Combines a Date with a time to create a DateTime.

downTo
Link copied to clipboard
common
infix fun Date.downTo(to: Date): DateDayProgression

Creates a progression of dates in descending order.

endOfDay
Link copied to clipboard
common
val Date.endOfDay: DateTime

The DateTime at the last representable instant of the day. Daylight savings transitions are not taken into account, so the returned date-time may not necessarily exist in all time zones.

endOfDayAt
Link copied to clipboard
common
fun Date.endOfDayAt(zone: TimeZone): ZonedDateTime

The ZonedDateTime at the last representable instant of the day in zone, taking into account any daylight savings transitions.

endOfMonth
Link copied to clipboard
common
val Date.endOfMonth: Date

The date at the end of the month that this date falls in.

endOfWeek
Link copied to clipboard
common
val Date.endOfWeek: Date

The date at the end of the ISO week that this date falls in.

fun Date.endOfWeek(settings: WeekSettings): Date

The date at the end of the week that this date falls in. The first day of the week will be determined by settings. The first day of the week will be determined by the system settings. 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.

fun Date.endOfWeek(locale: Locale): Date

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

endOfYear
Link copied to clipboard
common
val Date.endOfYear: Date

The date at the end of the year that this date falls in.

isInLeapYear
Link copied to clipboard
common
val Date.isInLeapYear: Boolean

Checks if this date falls within a leap year.

isLeapDay
Link copied to clipboard
common
val Date.isLeapDay: Boolean

Checks if this date is February 29.

lengthOfMonth
Link copied to clipboard
common
val Date.lengthOfMonth: Days

The length of this date's month in days.

lengthOfWeekBasedYear
Link copied to clipboard
common
val Date.lengthOfWeekBasedYear: Weeks

The length of the ISO week-based year that this date falls in, either 52 or 53 weeks.

lengthOfYear
Link copied to clipboard
common
val Date.lengthOfYear: Days

The length of this date's year in days.

next
Link copied to clipboard
common
fun Date.next(dayOfWeek: DayOfWeek): Date

The next date after this one that falls on dayOfWeek.

nextOrSame
Link copied to clipboard
common
fun Date.nextOrSame(dayOfWeek: DayOfWeek): Date

The next date that falls on dayOfWeek, or this date if it falls on the same day.

previous
Link copied to clipboard
common
fun Date.previous(dayOfWeek: DayOfWeek): Date

The last date before this one that falls on dayOfWeek.

previousOrSame
Link copied to clipboard
common
fun Date.previousOrSame(dayOfWeek: DayOfWeek): Date

The previous date that falls on dayOfWeek, or this date if it falls on the same day.

startOfDay
Link copied to clipboard
common
val Date.startOfDay: DateTime

The DateTime at the start of the day. Daylight savings transitions are not taken into account, so the returned date-time may not necessarily exist in all time zones.

startOfDayAt
Link copied to clipboard
common
fun Date.startOfDayAt(zone: TimeZone): ZonedDateTime

The ZonedDateTime at the start of the day in zone, taking into account any daylight savings transitions.

startOfMonth
Link copied to clipboard
common
val Date.startOfMonth: Date

The date at the start of the month that this date falls in.

startOfWeek
Link copied to clipboard
common
val Date.startOfWeek: Date

The date at the start of the ISO week that this date falls in.

fun Date.startOfWeek(settings: WeekSettings): Date

The date at the start of the week that this date falls in. The first day of the week will be determined by settings.

fun Date.startOfWeek(locale: Locale): Date

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

startOfYear
Link copied to clipboard
common
val Date.startOfYear: Date

The date at the start of the year that this date falls in.

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

Converts this date to an equivalent Java LocalDate.

toNSDateComponents
Link copied to clipboard
darwin
fun Date.toNSDateComponents(includeCalendar: Boolean = false): <ERROR CLASS>

Converts this date to an equivalent NSDateComponents object.

toWeekDate
Link copied to clipboard
common
inline fun <T> Date.toWeekDate(action: (year: Int, week: Int, day: Int) -> T): T

Converts this date to an ISO week date representation.

inline fun <T> Date.toWeekDate(settings: WeekSettings, action: (year: Int, week: Int, day: Int) -> T): T

Converts this date to a week date representation using the week definition in settings.

inline fun <T> Date.toWeekDate(locale: Locale, action: (year: Int, week: Int, day: Int) -> T): T

Converts this date to a week date representation using the week definition associated with the provided locale.

toYear
Link copied to clipboard
common
fun Date.toYear(): Year

Returns this date with the precision reduced to the year.

toYearMonth
Link copied to clipboard
common
fun Date.toYearMonth(): YearMonth

Returns this date with the precision reduced to the month.

until
Link copied to clipboard
common
infix fun Date.until(to: Date): DateRange

Creates a DateRange containing all of the days from this date up to, but not including to.

week
Link copied to clipboard
common
val Date.week: DateRange

The range defining the ISO week that this date falls within.

fun Date.week(settings: WeekSettings): DateRange

The range defining the week that this date falls within. The first day of the week will be determined by the provided settings.

fun Date.week(locale: Locale): DateRange

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

weekBasedYear
Link copied to clipboard
common
val Date.weekBasedYear: Int

The 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.

fun Date.weekBasedYear(settings: WeekSettings): Int

The 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.

fun Date.weekBasedYear(locale: Locale): Int

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.

weekOfMonth
Link copied to clipboard
common
val Date.weekOfMonth: Int

The week of the month, from 0-6, calculated using the ISO week definition.

fun Date.weekOfMonth(settings: WeekSettings): Int

The week of the month, from 0-6, calculated using the week definition in settings.

fun Date.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 Date.weekOfWeekBasedYear: Int

The week number used in the ISO week date system.

fun Date.weekOfWeekBasedYear(settings: WeekSettings): Int

The week number of the week-based year, calculated using the week definition in settings.

fun Date.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 Date.weekOfYear: Int

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

fun Date.weekOfYear(settings: WeekSettings): Int

The 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.

fun Date.weekOfYear(locale: Locale): Int

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.