Optional
durationPeriod
Get the day of the month (1-30ish).
DateTime.local(2017, 5, 25).day //=> 25
Returns the number of days in this DateTime's month
DateTime.local(2016, 2).daysInMonth //=> 29
DateTime.local(2016, 3).daysInMonth //=> 31
Returns the number of days in this DateTime's year
DateTime.local(2016).daysInYear //=> 366
DateTime.local(2013).daysInYear //=> 365
Get the hour of the day (0-23).
DateTime.local(2017, 5, 25, 9).hour //=> 9
Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
Returns an error code if this DateTime is invalid, or null if the DateTime is valid
Get whether the DateTime is in a DST.
Returns true if this DateTime is in a leap year, false otherwise
DateTime.local(2016).isInLeapYear //=> true
DateTime.local(2013).isInLeapYear //=> false
Get whether this zone's offset ever changes, as in a DST.
Returns whether the DateTime is valid. Invalid DateTimes occur when:
Returns true if this date is on a weekend, according to the locale, false otherwise
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.
Get the week year, according to the locale. Different locales assign week numbers (and therefore week years) differently, see localWeekNumber.
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.
Get the locale of a DateTime, such as 'en-GB'. The locale is used when formatting the DateTime
Get the millisecond of the second (0-999).
DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
Get the minute of the hour (0-59).
DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
Get the month (1-12).
DateTime.local(2017, 5, 25).month //=> 5
Get the human readable long month name, such as 'October'. Defaults to the system's locale if no locale has been specified
DateTime.local(2017, 10, 30).monthLong //=> October
Get the human readable short month name, such as 'Oct'. Defaults to the system's locale if no locale has been specified
DateTime.local(2017, 10, 30).monthShort //=> Oct
Get the numbering system of a DateTime, such as 'beng'. The numbering system is used when formatting the DateTime
Get the UTC offset of this DateTime in minutes
DateTime.now().offset //=> -240
DateTime.utc().offset //=> 0
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
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
Get the ordinal (meaning the day of the year)
DateTime.local(2017, 5, 25).ordinal //=> 145
Get the output calendar of a DateTime, such as 'islamic'. The output calendar is used when formatting the DateTime
Get the quarter
DateTime.local(2017, 5, 25).quarter //=> 2
Get the second of the minute (0-59).
DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
Get the week number of the week year (1-52ish).
https://en.wikipedia.org/wiki/ISO_week_date
DateTime.local(2017, 5, 25).weekNumber //=> 21
Get the week year
https://en.wikipedia.org/wiki/ISO_week_date
DateTime.local(2014, 12, 31).weekYear //=> 2015
Get the day of the week. 1 is Monday and 7 is Sunday
Get the human readable long weekday, such as 'Monday'. Defaults to the system's locale if no locale has been specified
DateTime.local(2017, 10, 30).weekdayLong //=> Monday
Get the human readable short weekday, such as 'Mon'. Defaults to the system's locale if no locale has been specified
DateTime.local(2017, 10, 30).weekdayShort //=> Mon
Returns the number of weeks in this DateTime's local week year
DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
Returns the number of weeks in this DateTime's year
https://en.wikipedia.org/wiki/ISO_week_date
DateTime.local(2004).weeksInWeekYear //=> 53
DateTime.local(2013).weeksInWeekYear //=> 52
Get the year
DateTime.local(2017, 5, 25).year //=> 2017
Get the time zone associated with this DateTime.
Get the name of the time zone.
Return the difference between two DateTimes as a Duration.
the DateTime to compare this one to
Optional
unit: DurationUnitsthe unit or array of units to include in the duration. Defaults to ['milliseconds'].
Optional
opts: DiffOptionsoptions that affect the creation of the Duration
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
Optional
unit: DurationUnitsthe unit(s) to include in the duration. Defaults to ['milliseconds'].
Optional
opts: DiffOptionsoptions that affect the creation of the Duration
"Set" this DateTime to the end (meaning the last millisecond) of a unit of time
The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
Optional
opts: _UseLocaleWeekOptionoptions
DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
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.
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.
the other DateTime
the unit of time to check sameness on
Optional
opts: _UseLocaleWeekOptionDateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
See DateTime.plus
The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
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.
The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
DateTime.now().plus(123) //~> in 123 milliseconds
DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
DateTime.now().plus({ days: 1 }) //~> this time tomorrow
DateTime.now().plus({ days: -1 }) //~> this time yesterday
DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
Returns the resolved Intl options for this DateTime. This is useful in understanding the behavior of formatting methods
Optional
opts: LocaleOptions | DateTimeFormatOptionsthe same options as toLocaleString
"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
.
dt.set({ year: 2017 })
dt.set({ hour: 8, minute: 30 })
dt.set({ weekday: 5 })
dt.set({ year: 2005, ordinal: 234 })
"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.
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: ZoneOptionsoptions
"Set" this DateTime to the beginning of the given unit.
The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
Optional
opts: _UseLocaleWeekOptionoptions
DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
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.
the format string
Optional
opts: LocaleOptionsopts to override the configuration options on this DateTime
DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
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.
https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
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
Optional
opts: ToISOTimeOptionsDateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
Returns an ISO 8601-compliant string representation of this DateTime's date component
Optional
opts: ToISODateOptionsoptions
DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
Returns an ISO 8601-compliant string representation of this DateTime's time component
Optional
opts: ToISOTimeOptionsoptions
DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
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
Optional
opts: DateTimeFormatOptionsDateTime.now().toLocaleParts(); //=> [
//=> { type: 'day', value: '25' },
//=> { type: 'literal', value: '/' },
//=> { type: 'month', value: '05' },
//=> { type: 'literal', value: '/' },
//=> { type: 'year', value: '1982' }
//=> ]
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
Optional
formatOpts: DateTimeFormatOptionsIntl.DateTimeFormat constructor options and configuration options
Optional
opts: LocaleOptionsopts to override the configuration options on this DateTime
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
DateTime.now().toLocaleString(); //=> 4/20/2017
DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); //=> '11:32'
Returns a JavaScript object with this DateTime's year, month, day, and so on.
Optional
opts: { options for generating the object
Optional
includeInclude configuration attributes in the output
false
DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
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.
Optional
options: ToRelativeOptionsDateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
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.
Optional
options: ToRelativeCalendarOptionsDateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
Returns a string representation of this DateTime for use in SQL DateTime
Optional
opts: ToSQLOptionsDateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
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 Time
Optional
opts: ToSQLOptionsDateTime.utc().toSQL() //=> '05:15:16.345'
DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
"Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
Equivalent to DateTime.setZone('utc')
Optional
offset: numberoptionally, an offset from UTC in minutes. Defaults to 0.
Optional
opts: ZoneOptionsoptions to pass to setZone()
. Defaults to {}.
Returns the epoch milliseconds of this DateTime. Alias of DateTime.toMillis
DateTimeWithPeriod