DateTimeWithPeriod

interface DateTimeWithDuration {
    duration?: Duration<boolean>;
    get day(): IfValid<DayNumbers, number, IsValid>;
    get daysInMonth(): IfValid<PossibleDaysInMonth, undefined, IsValid>;
    get daysInYear(): IfValid<PossibleDaysInYear, number, IsValid>;
    get hour(): IfValid<HourNumbers, number, IsValid>;
    get invalidExplanation(): IfValid<null, string, IsValid>;
    get invalidReason(): IfValid<null, string, IsValid>;
    get isInDST(): IfValid<boolean, false, IsValid>;
    get isInLeapYear(): boolean;
    get isOffsetFixed(): IfValid<boolean, null, IsValid>;
    get isValid(): IfValid<true, false, IsValid>;
    get isWeekend(): IfValid<boolean, false, IsValid>;
    get localWeekNumber(): IfValid<number, number, IsValid>;
    get localWeekYear(): IfValid<number, number, IsValid>;
    get localWeekday(): IfValid<WeekdayNumbers, number, IsValid>;
    get locale(): IfValid<string, null, IsValid>;
    get millisecond(): IfValid<number, number, IsValid>;
    get minute(): IfValid<SecondNumbers, number, IsValid>;
    get month(): IfValid<MonthNumbers, number, IsValid>;
    get monthLong(): IfValid<string, null, IsValid>;
    get monthShort(): IfValid<string, null, IsValid>;
    get numberingSystem(): IfValid<string, null, IsValid>;
    get offset(): IfValid<number, number, IsValid>;
    get offsetNameLong(): IfValid<string, null, IsValid>;
    get offsetNameShort(): IfValid<string, null, IsValid>;
    get ordinal(): IfValid<number, number, IsValid>;
    get outputCalendar(): IfValid<string, null, IsValid>;
    get quarter(): IfValid<QuarterNumbers, number, IsValid>;
    get second(): IfValid<SecondNumbers, number, IsValid>;
    get weekNumber(): IfValid<WeekNumbers, number, IsValid>;
    get weekYear(): IfValid<number, number, IsValid>;
    get weekday(): IfValid<WeekdayNumbers, number, IsValid>;
    get weekdayLong(): IfValid<string, null, IsValid>;
    get weekdayShort(): IfValid<string, null, IsValid>;
    get weeksInLocalWeekYear(): IfValid<PossibleWeeksInYear, number, IsValid>;
    get weeksInWeekYear(): IfValid<PossibleWeeksInYear, number, IsValid>;
    get year(): IfValid<number, number, IsValid>;
    get zone(): Zone<IsValid>;
    get zoneName(): IfValid<string, null, IsValid>;
    diff(otherDateTime, unit?, opts?): Duration<boolean>;
    diffNow(unit?, opts?): Duration<true>;
    endOf(unit, opts?): this;
    equals(other): boolean;
    get(unit): number;
    getPossibleOffsets(): DateTimeWithDuration[];
    hasSame(otherDateTime, unit, opts?): boolean;
    minus(duration): this;
    plus(duration): this;
    reconfigure(properties): this;
    resolvedLocaleOptions(opts?): Required<LocaleOptions>;
    set(values): this;
    setLocale(locale): this;
    setZone(zone?, opts?): DateTime<true> | DateTime<false>;
    startOf(unit, opts?): this;
    toBSON(): Date;
    toFormat(fmt, opts?): string;
    toHTTP(): string;
    toISO(opts?): string;
    toISODate(opts?): string;
    toISOTime(opts?): string;
    toISOWeekDate(): string;
    toJSDate(): Date;
    toJSON(): string;
    toLocal(): this;
    toLocaleParts(opts?): DateTimeFormatPart[];
    toLocaleString(formatOpts?, opts?): string;
    toMillis(): number;
    toObject<IncludeConfig>(opts?): _ToObjectOutput<IncludeConfig> | Partial<_ToObjectOutput<IncludeConfig>>;
    toRFC2822(): string;
    toRelative(options?): string;
    toRelativeCalendar(options?): string;
    toSQL(opts?): string;
    toSQLDate(): string;
    toSQLTime(opts?): string;
    toSeconds(): number;
    toString(): string;
    toUTC(offset?, opts?): this;
    toUnixInteger(): number;
    until(otherDateTime): Interval<true> | DateTime<false>;
    valueOf(): number;
}

Hierarchy

  • DateTime
    • DateTimeWithDuration

Properties

duration?: Duration<boolean>

Period

Accessors

  • get day(): IfValid<DayNumbers, number, IsValid>
  • Get the day of the month (1-30ish).

    Returns IfValid<DayNumbers, number, IsValid>

    Example

    DateTime.local(2017, 5, 25).day //=> 25
    
  • get daysInMonth(): IfValid<PossibleDaysInMonth, undefined, IsValid>
  • Returns the number of days in this DateTime's month

    Returns IfValid<PossibleDaysInMonth, undefined, IsValid>

    Example

    DateTime.local(2016, 2).daysInMonth //=> 29
    

    Example

    DateTime.local(2016, 3).daysInMonth //=> 31
    
  • get daysInYear(): IfValid<PossibleDaysInYear, number, IsValid>
  • Returns the number of days in this DateTime's year

    Returns IfValid<PossibleDaysInYear, number, IsValid>

    Example

    DateTime.local(2016).daysInYear //=> 366
    

    Example

    DateTime.local(2013).daysInYear //=> 365
    
  • get hour(): IfValid<HourNumbers, number, IsValid>
  • Get the hour of the day (0-23).

    Returns IfValid<HourNumbers, number, IsValid>

    Example

    DateTime.local(2017, 5, 25, 9).hour //=> 9
    
  • get invalidExplanation(): IfValid<null, string, IsValid>
  • Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid

    Returns IfValid<null, string, IsValid>

  • get invalidReason(): IfValid<null, string, IsValid>
  • Returns an error code if this DateTime is invalid, or null if the DateTime is valid

    Returns IfValid<null, string, IsValid>

  • get isInDST(): IfValid<boolean, false, IsValid>
  • Get whether the DateTime is in a DST.

    Returns IfValid<boolean, false, IsValid>

  • get isInLeapYear(): boolean
  • Returns true if this DateTime is in a leap year, false otherwise

    Returns boolean

    Example

    DateTime.local(2016).isInLeapYear //=> true
    

    Example

    DateTime.local(2013).isInLeapYear //=> false
    
  • get isOffsetFixed(): IfValid<boolean, null, IsValid>
  • Get whether this zone's offset ever changes, as in a DST.

    Returns IfValid<boolean, null, IsValid>

  • get isValid(): IfValid<true, false, IsValid>
  • Returns whether the DateTime is valid. Invalid DateTimes occur when:

    • The DateTime was created from invalid calendar information, such as the 13th month or February 30
    • The DateTime was created by an operation on another invalid date

    Returns IfValid<true, false, IsValid>

  • get isWeekend(): IfValid<boolean, false, IsValid>
  • Returns true if this date is on a weekend, according to the locale, false otherwise

    Returns IfValid<boolean, false, IsValid>

  • get localWeekNumber(): IfValid<number, number, IsValid>
  • Get the week number of the week year, according to the locale. Different locales assign week numbers differently. The week can start on different days of the week (see localWeekday), and because a different number of days is required for a week to count as the first week of a year.

    Returns IfValid<number, number, IsValid>

  • get localWeekYear(): IfValid<number, number, IsValid>
  • Get the week year, according to the locale. Different locales assign week numbers (and therefore week years) differently, see localWeekNumber.

    Returns IfValid<number, number, IsValid>

  • get localWeekday(): IfValid<WeekdayNumbers, number, IsValid>
  • Get the day of the week, according to the locale. 1 is the first day of the week, and 7 is the last day of the week. If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1.

    Returns IfValid<WeekdayNumbers, number, IsValid>

  • get locale(): IfValid<string, null, IsValid>
  • Get the locale of a DateTime, such as 'en-GB'. The locale is used when formatting the DateTime

    Returns IfValid<string, null, IsValid>

  • get millisecond(): IfValid<number, number, IsValid>
  • Get the millisecond of the second (0-999).

    Returns IfValid<number, number, IsValid>

    Example

    DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
    
  • get minute(): IfValid<SecondNumbers, number, IsValid>
  • Get the minute of the hour (0-59).

    Returns IfValid<SecondNumbers, number, IsValid>

    Example

    DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
    
  • get month(): IfValid<MonthNumbers, number, IsValid>
  • Get the month (1-12).

    Returns IfValid<MonthNumbers, number, IsValid>

    Example

    DateTime.local(2017, 5, 25).month //=> 5
    
  • get monthLong(): IfValid<string, null, IsValid>
  • Get the human readable long month name, such as 'October'. Defaults to the system's locale if no locale has been specified

    Returns IfValid<string, null, IsValid>

    Example

    DateTime.local(2017, 10, 30).monthLong //=> October
    
  • get monthShort(): IfValid<string, null, IsValid>
  • Get the human readable short month name, such as 'Oct'. Defaults to the system's locale if no locale has been specified

    Returns IfValid<string, null, IsValid>

    Example

    DateTime.local(2017, 10, 30).monthShort //=> Oct
    
  • get numberingSystem(): IfValid<string, null, IsValid>
  • Get the numbering system of a DateTime, such as 'beng'. The numbering system is used when formatting the DateTime

    Returns IfValid<string, null, IsValid>

  • get offset(): IfValid<number, number, IsValid>
  • Get the UTC offset of this DateTime in minutes

    Returns IfValid<number, number, IsValid>

    Example

    DateTime.now().offset //=> -240
    

    Example

    DateTime.utc().offset //=> 0
    
  • get offsetNameLong(): IfValid<string, null, IsValid>
  • Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time". Defaults to the system's locale if no locale has been specified

    Returns IfValid<string, null, IsValid>

  • get offsetNameShort(): IfValid<string, null, IsValid>
  • Get the short human name for the zone's current offset, for example "EST" or "EDT". Defaults to the system's locale if no locale has been specified

    Returns IfValid<string, null, IsValid>

  • get ordinal(): IfValid<number, number, IsValid>
  • Get the ordinal (meaning the day of the year)

    Returns IfValid<number, number, IsValid>

    Example

    DateTime.local(2017, 5, 25).ordinal //=> 145
    
  • get outputCalendar(): IfValid<string, null, IsValid>
  • Get the output calendar of a DateTime, such as 'islamic'. The output calendar is used when formatting the DateTime

    Returns IfValid<string, null, IsValid>

  • get quarter(): IfValid<QuarterNumbers, number, IsValid>
  • Get the quarter

    Returns IfValid<QuarterNumbers, number, IsValid>

    Example

    DateTime.local(2017, 5, 25).quarter //=> 2
    
  • get second(): IfValid<SecondNumbers, number, IsValid>
  • Get the second of the minute (0-59).

    Returns IfValid<SecondNumbers, number, IsValid>

    Example

    DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
    
  • get weekNumber(): IfValid<WeekNumbers, number, IsValid>
  • Get the week number of the week year (1-52ish).

    Returns IfValid<WeekNumbers, number, IsValid>

    See

    https://en.wikipedia.org/wiki/ISO_week_date

    Example

    DateTime.local(2017, 5, 25).weekNumber //=> 21
    
  • get weekYear(): IfValid<number, number, IsValid>
  • Get the week year

    Returns IfValid<number, number, IsValid>

    See

    https://en.wikipedia.org/wiki/ISO_week_date

    Example

    DateTime.local(2014, 12, 31).weekYear //=> 2015
    
  • get weekday(): IfValid<WeekdayNumbers, number, IsValid>
  • Get the day of the week. 1 is Monday and 7 is Sunday

    Returns IfValid<WeekdayNumbers, number, IsValid>

    See

    https://en.wikipedia.org/wiki/ISO_week_date

    Example

    DateTime.local(2014, 11, 31).weekday //=> 4
    
  • get weekdayLong(): IfValid<string, null, IsValid>
  • Get the human readable long weekday, such as 'Monday'. Defaults to the system's locale if no locale has been specified

    Returns IfValid<string, null, IsValid>

    Example

    DateTime.local(2017, 10, 30).weekdayLong //=> Monday
    
  • get weekdayShort(): IfValid<string, null, IsValid>
  • Get the human readable short weekday, such as 'Mon'. Defaults to the system's locale if no locale has been specified

    Returns IfValid<string, null, IsValid>

    Example

    DateTime.local(2017, 10, 30).weekdayShort //=> Mon
    
  • get weeksInLocalWeekYear(): IfValid<PossibleWeeksInYear, number, IsValid>
  • Returns the number of weeks in this DateTime's local week year

    Returns IfValid<PossibleWeeksInYear, number, IsValid>

    Example

    DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
    

    Example

    DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
    
  • get weeksInWeekYear(): IfValid<PossibleWeeksInYear, number, IsValid>
  • Returns the number of weeks in this DateTime's year

    Returns IfValid<PossibleWeeksInYear, number, IsValid>

    See

    https://en.wikipedia.org/wiki/ISO_week_date

    Example

    DateTime.local(2004).weeksInWeekYear //=> 53
    

    Example

    DateTime.local(2013).weeksInWeekYear //=> 52
    
  • get year(): IfValid<number, number, IsValid>
  • Get the year

    Returns IfValid<number, number, IsValid>

    Example

    DateTime.local(2017, 5, 25).year //=> 2017
    
  • get zone(): Zone<IsValid>
  • Get the time zone associated with this DateTime.

    Returns Zone<IsValid>

  • get zoneName(): IfValid<string, null, IsValid>
  • Get the name of the time zone.

    Returns IfValid<string, null, IsValid>

Methods

  • Return the difference between two DateTimes as a Duration.

    Parameters

    • otherDateTime: DateTime<boolean>

      the DateTime to compare this one to

    • Optional unit: DurationUnits

      the unit or array of units to include in the duration. Defaults to ['milliseconds'].

    • Optional opts: DiffOptions

      options that affect the creation of the Duration

    Returns Duration<boolean>

    Example

    let i1 = DateTime.fromISO('1982-05-25T09:45'),
    i2 = DateTime.fromISO('1983-10-14T10:30');
    i2.diff(i1).toObject() //=> { milliseconds: 43807500000 }
    i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 }
    i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 }
    i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 }
  • Return the difference between this DateTime and right now. See DateTime.diff

    Parameters

    • Optional unit: DurationUnits

      the unit(s) to include in the duration. Defaults to ['milliseconds'].

    • Optional opts: DiffOptions

      options that affect the creation of the Duration

    Returns Duration<true>

  • "Set" this DateTime to the end (meaning the last millisecond) of a unit of time

    Parameters

    • unit: DateTimeUnit

      The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.

    • Optional opts: _UseLocaleWeekOption

      options

    Returns this

    Example

    DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
    

    Example

    DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
    

    Example

    DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
    

    Example

    DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
    

    Example

    DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
    
  • An equality check. Two DateTimes are equal if and only if they represent the same millisecond, have the same zone and location, and are both valid. To compare just the millisecond values, use +dt1 === +dt2.

    Parameters

    • other: DateTime<boolean>

      the other DateTime

    Returns boolean

  • Get the value of unit.

    Parameters

    • unit: keyof DateTime<boolean>

      a unit such as 'minute' or 'day'

    Returns number

    Example

    DateTime.local(2017, 7, 4).get('month'); //=> 7
    

    Example

    DateTime.local(2017, 7, 4).get('day'); //=> 4
    
  • Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC in this DateTime's zone. During DST changes local time can be ambiguous, for example 2023-10-29T02:30:00 in Europe/Berlin can have offset +01:00 or +02:00. This method will return both possible DateTimes if this DateTime's local time is ambiguous.

    Returns DateTimeWithDuration[]

  • Return whether this DateTime is in the same unit of time as another DateTime. Note that time zones are ignored in this comparison, which compares the local calendar time. Use DateTime.setZone to convert one of the dates if needed.

    Parameters

    • otherDateTime: DateTime<boolean>

      the other DateTime

    • unit: DateTimeUnit

      the unit of time to check sameness on

    • Optional opts: _UseLocaleWeekOption

    Returns boolean

    Example

    DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
    
  • Parameters

    • duration: DurationLike

      The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()

    Returns this

  • Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, dt.plus({ hours: 24 }) may result in a different time than dt.plus({ days: 1 }) if there's a DST shift in between.

    Parameters

    • duration: DurationLike

      The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()

    Returns this

    Example

    DateTime.now().plus(123) //~> in 123 milliseconds
    

    Example

    DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
    

    Example

    DateTime.now().plus({ days: 1 }) //~> this time tomorrow
    

    Example

    DateTime.now().plus({ days: -1 }) //~> this time yesterday
    

    Example

    DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
    

    Example

    DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
    
  • "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.

    Parameters

    • properties: LocaleOptions

      the properties to set

    Returns this

    Example

    DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' })
    
  • Returns the resolved Intl options for this DateTime. This is useful in understanding the behavior of formatting methods

    Parameters

    • Optional opts: LocaleOptions | DateTimeFormatOptions

      the same options as toLocaleString

    Returns Required<LocaleOptions>

  • "Set" the values of specified units. Returns a newly-constructed DateTime. You can only set units with this method; for "setting" metadata, see DateTime.reconfigure and DateTime.setZone.

    This method also supports setting locale-based week units, i.e. localWeekday, localWeekNumber and localWeekYear. They cannot be mixed with ISO-week units like weekday.

    Parameters

    • values: DateObjectUnits

    Returns this

    Example

    dt.set({ year: 2017 })
    

    Example

    dt.set({ hour: 8, minute: 30 })
    

    Example

    dt.set({ weekday: 5 })
    

    Example

    dt.set({ year: 2005, ordinal: 234 })
    
  • "Set" the locale. Returns a newly-constructed DateTime. Just a convenient alias for reconfigure({ locale })

    Parameters

    • locale: string

    Returns this

    Example

    DateTime.local(2017, 5, 25).setLocale('en-GB')
    
  • "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime.

    By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations, as with DateTime.plus. You may wish to use DateTime.toLocal and DateTime.toUTC which provide simple convenience wrappers for commonly used zones.

    Parameters

    • Optional zone: string | Zone<boolean>

      a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'. You may also supply an instance of a Zone class. Defaults to 'local'.

    • Optional opts: ZoneOptions

      options

    Returns DateTime<true> | DateTime<false>

  • "Set" this DateTime to the beginning of the given unit.

    Parameters

    • unit: DateTimeUnit

      The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.

    • Optional opts: _UseLocaleWeekOption

      options

    Returns this

    Example

    DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
    

    Example

    DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
    

    Example

    DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
    

    Example

    DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
    

    Example

    DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
    
  • Returns a BSON-serializable equivalent to this DateTime.

    Returns Date

  • Returns a string representation of this DateTime formatted according to the specified format string. You may not want this. See DateTime.toLocaleString for a more flexible formatting tool. For a table of tokens and their interpretations, see here. Defaults to en-US if no locale has been specified, regardless of the system's locale.

    Parameters

    • fmt: string

      the format string

    • Optional opts: LocaleOptions

      opts to override the configuration options on this DateTime

    Returns string

    Example

    DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
    

    Example

    DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
    

    Example

    DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
    

    Example

    DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
    
  • Returns a string representation of this DateTime appropriate for use in HTTP headers. Specifically, the string conforms to RFC 1123.

    Returns string

    See

    https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1

    Example

    DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
    

    Example

    DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT'
    
  • Returns an ISO 8601-compliant string representation of this DateTime

    Parameters

    • Optional opts: ToISOTimeOptions

    Returns string

    Example

    DateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
    

    Example

    DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
    

    Example

    DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
    

    Example

    DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
    
  • Returns an ISO 8601-compliant string representation of this DateTime's date component

    Parameters

    • Optional opts: ToISODateOptions

      options

    Returns string

    Example

    DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
    

    Example

    DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
    
  • Returns an ISO 8601-compliant string representation of this DateTime's time component

    Parameters

    • Optional opts: ToISOTimeOptions

      options

    Returns string

    Example

    DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
    

    Example

    DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
    

    Example

    DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
    

    Example

    DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
    
  • Returns an ISO 8601-compliant string representation of this DateTime's week date

    Returns string

    Example

    DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2'
    
  • Returns a JavaScript Date equivalent to this DateTime.

    Returns Date

  • Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.

    Returns string

  • "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.

    Equivalent to setZone('local')

    Returns this

  • Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output. Defaults to the system's locale if no locale has been specified

    Parameters

    • Optional opts: DateTimeFormatOptions

    Returns DateTimeFormatPart[]

    See

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts

    Example

    DateTime.now().toLocaleParts(); //=> [
    //=> { type: 'day', value: '25' },
    //=> { type: 'literal', value: '/' },
    //=> { type: 'month', value: '05' },
    //=> { type: 'literal', value: '/' },
    //=> { type: 'year', value: '1982' }
    //=> ]

    Example

    DateTime.invalid('').toLocaleParts(); //=> []
    
  • Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as DateTime.DATE_FULL or DateTime.TIME_SIMPLE of the DateTime in the assigned locale. Defaults to the system's locale if no locale has been specified

    Parameters

    • Optional formatOpts: DateTimeFormatOptions

      Intl.DateTimeFormat constructor options and configuration options

    • Optional opts: LocaleOptions

      opts to override the configuration options on this DateTime

    Returns string

    See

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat

    Example

    DateTime.now().toLocaleString(); //=> 4/20/2017
    

    Example

    DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
    

    Example

    DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
    

    Example

    DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
    

    Example

    DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
    

    Example

    DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
    

    Example

    DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
    

    Example

    DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
    

    Example

    DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); //=> '11:32'
    
  • Returns the epoch milliseconds of this DateTime.

    Returns number

  • Returns a JavaScript object with this DateTime's year, month, day, and so on.

    Type Parameters

    • IncludeConfig extends boolean

    Parameters

    • Optional opts: {
          includeConfig?: IncludeConfig;
      }

      options for generating the object

      • Optional includeConfig?: IncludeConfig

        Include configuration attributes in the output

        Default Value

        false
        

    Returns _ToObjectOutput<IncludeConfig> | Partial<_ToObjectOutput<IncludeConfig>>

    Example

    DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
    
  • Returns an RFC 2822-compatible string representation of this DateTime, always in UTC

    Returns string

    Example

    DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000'
    

    Example

    DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400'
    
  • Returns a string representation of this time relative to now, such as "in two days". Can only internationalize if your platform supports Intl.RelativeTimeFormat. Rounds down by default.

    Parameters

    • Optional options: ToRelativeOptions

    Returns string

    Example

    DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
    

    Example

    DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
    

    Example

    DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
    

    Example

    DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
    

    Example

    DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
    

    Example

    DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
    
  • Returns a string representation of this date relative to today, such as "yesterday" or "next month". Only internationalizes on platforms that support Intl.RelativeTimeFormat.

    Parameters

    • Optional options: ToRelativeCalendarOptions

    Returns string

    Example

    DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
    

    Example

    DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
    

    Example

    DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
    

    Example

    DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
    
  • Returns a string representation of this DateTime for use in SQL DateTime

    Parameters

    • Optional opts: ToSQLOptions

    Returns string

    Example

    DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
    

    Example

    DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
    

    Example

    DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
    

    Example

    DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York'
    
  • Returns a string representation of this DateTime appropriate for use in SQL Date

    Returns string

    Example

    DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13'
    
  • Returns a string representation of this DateTime appropriate for use in SQL Time

    Parameters

    • Optional opts: ToSQLOptions

    Returns string

    Example

    DateTime.utc().toSQL() //=> '05:15:16.345'
    

    Example

    DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
    

    Example

    DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
    

    Example

    DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
    
  • Returns the epoch seconds of this DateTime.

    Returns number

  • Returns a string representation of this DateTime appropriate for debugging

    Returns string

  • "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.

    Equivalent to DateTime.setZone('utc')

    Parameters

    • Optional offset: number

      optionally, an offset from UTC in minutes. Defaults to 0.

    • Optional opts: ZoneOptions

      options to pass to setZone(). Defaults to {}.

    Returns this

  • Returns the epoch seconds (as a whole number) of this DateTime.

    Returns number

  • Return an Interval spanning between this DateTime and another DateTime

    Parameters

    • otherDateTime: DateTime<boolean>

      the other end point of the Interval

    Returns Interval<true> | DateTime<false>

  • Returns the epoch milliseconds of this DateTime. Alias of DateTime.toMillis

    Returns number