On this page
Sommatic Docs
Open portal

Luxon dates

Dates and times with Luxon: $now and $today are Luxon DateTime values, so every method below works on them.

View as Markdown
Open in

Version 3.7.2 MIT Official documentation

$now uses the server time zone: set the zone you need before formatting.

JavaScript
{{ $now.setZone('America/Bogota').toFormat('yyyy-LL-dd HH:mm') }}

Create a DateTime

DateTime.buildFormatParser(fmt, options = {})

Build a parser for fmt using the given locale. This parser can be passed to DateTime.fromFormatParser to a parse a date in this format. This can be used to optimize cases where many dates need to be parsed in a specific format.

  • fmt String the format the string is expected to be in (see description)
  • options Object options used to set locale and numberingSystem for parser

→ TokenParser

DateTime.DATE_FULL

DateTime#toLocaleString format like 'October 14, 1983'

DateTime.DATE_HUGE

DateTime#toLocaleString format like 'Tuesday, October 14, 1983'

DateTime.DATE_MED

DateTime#toLocaleString format like 'Oct 14, 1983'

DateTime.DATE_MED_WITH_WEEKDAY

DateTime#toLocaleString format like 'Fri, Oct 14, 1983'

DateTime.DATE_SHORT

DateTime#toLocaleString format like 10/14/1983

DateTime.DATETIME_FULL

DateTime#toLocaleString format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.

DateTime.DATETIME_FULL_WITH_SECONDS

DateTime#toLocaleString format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.

DateTime.DATETIME_HUGE

DateTime#toLocaleString format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.

DateTime.DATETIME_HUGE_WITH_SECONDS

DateTime#toLocaleString format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.

DateTime.DATETIME_MED

DateTime#toLocaleString format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.

DateTime.DATETIME_MED_WITH_SECONDS

DateTime#toLocaleString format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.

DateTime.DATETIME_MED_WITH_WEEKDAY

DateTime#toLocaleString format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.

DateTime.DATETIME_SHORT

DateTime#toLocaleString format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.

DateTime.DATETIME_SHORT_WITH_SECONDS

DateTime#toLocaleString format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.

DateTime.expandFormat(fmt, localeOpts = {})

Produce the the fully expanded format token for the locale Does NOT quote characters, so quoted tokens will not round trip correctly

  • fmt
  • localeOpts

→ string

DateTime.fromFormat(text, fmt, opts = {})

Create a DateTime from an input string and format string. Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations, see here.

  • text string the string to parse
  • fmt string the format the string is expected to be in (see the link below for the formats)
  • opts Object options to affect the creation
  • opts.zone string|Zone Optional Default 'local' use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
  • opts.setZone boolean Optional Default false override the zone with a zone specified in the string itself, if it specifies one
  • opts.locale string Optional Default 'en-US' a locale string to use when parsing. Will also set the DateTime to this locale
  • opts.numberingSystem string the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
  • opts.weekSettings string the week settings to set on the resulting DateTime instance
  • opts.outputCalendar string the output calendar to set on the resulting DateTime instance

→ DateTime

DateTime.fromFormatExplain(text, fmt, options = {})

Explain how a string would be parsed by fromFormat()

  • text string the string to parse
  • fmt string the format the string is expected to be in (see description)
  • options Object options taken by fromFormat()

→ Object

DateTime.fromFormatParser(text, formatParser, opts = {})

Create a DateTime from an input string and format parser.

The format parser must have been created with the same locale as this call.

  • text String the string to parse
  • formatParser TokenParser parser from `DateTime.buildFormatParser`
  • opts Object options taken by fromFormat()

→ DateTime

DateTime.fromHTTP(text, opts = {})

Create a DateTime from an HTTP header date

  • text string the HTTP header date
  • opts Object options to affect the creation
  • opts.zone string|Zone Optional Default 'local' convert the time to this zone. Since HTTP dates are always in UTC, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
  • opts.setZone boolean Optional Default false override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC, so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods.
  • opts.locale string Optional Default 'system's locale' a locale to set on the resulting DateTime instance
  • opts.outputCalendar string the output calendar to set on the resulting DateTime instance
  • opts.numberingSystem string the numbering system to set on the resulting DateTime instance
  • opts.weekSettings string the week settings to set on the resulting DateTime instance

→ DateTime

{{ $now.constructor.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT') }}
Result DateTime
"1994-11-06T08:49:37.000Z"
{{ $now.constructor.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT') }}
Result DateTime
"1994-11-06T08:49:37.000Z"
{{ $now.constructor.fromHTTP('Sun Nov  6 08:49:37 1994') }}
Result DateTime
"1994-11-06T08:49:37.000Z"

DateTime.fromISO(text, opts = {})

Create a DateTime from an ISO 8601 string

  • text string the ISO string
  • opts Object options to affect the creation
  • opts.zone string|Zone Optional Default 'local' use this zone if no offset is specified in the input string itself. Will also convert the time to this zone
  • opts.setZone boolean Optional Default false override the zone with a fixed-offset zone specified in the string itself, if it specifies one
  • opts.locale string Optional Default 'system's locale' a locale to set on the resulting DateTime instance
  • opts.outputCalendar string Optional the output calendar to set on the resulting DateTime instance
  • opts.numberingSystem string Optional the numbering system to set on the resulting DateTime instance
  • opts.weekSettings string Optional the week settings to set on the resulting DateTime instance

→ DateTime

{{ $now.constructor.fromISO('2016-05-25T09:08:34.123') }}
Result DateTime
"2016-05-25T09:08:34.123Z"
{{ $now.constructor.fromISO('2016-05-25T09:08:34.123+06:00') }}
Result DateTime
"2016-05-25T03:08:34.123Z"
{{ $now.constructor.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true}) }}
Result DateTime
"2016-05-25T09:08:34.123+06:00"

DateTime.fromJSDate(date, options = {})

Create a DateTime from a JavaScript Date object. Uses the default zone.

  • date Date a JavaScript Date object
  • options Object configuration options for the DateTime
  • options.zone string|Zone Optional Default 'local' the zone to place the DateTime into

→ DateTime

DateTime.fromMillis(milliseconds, options = {})

Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.

  • milliseconds number a number of milliseconds since 1970 UTC
  • options Object configuration options for the DateTime
  • options.zone string|Zone Optional Default 'local' the zone to place the DateTime into
  • options.locale string Optional a locale to set on the resulting DateTime instance
  • options.outputCalendar string the output calendar to set on the resulting DateTime instance
  • options.numberingSystem string the numbering system to set on the resulting DateTime instance
  • options.weekSettings string the week settings to set on the resulting DateTime instance

→ DateTime

DateTime.fromObject(obj, opts = {})

Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.

  • obj Object the object to create the DateTime from
  • obj.year number a year, such as 1987
  • obj.month number a month, 1-12
  • obj.day number a day of the month, 1-31, depending on the month
  • obj.ordinal number day of the year, 1-365 or 366
  • obj.weekYear number an ISO week year
  • obj.weekNumber number an ISO week number, between 1 and 52 or 53, depending on the year
  • obj.weekday number an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
  • obj.localWeekYear number a week year, according to the locale
  • obj.localWeekNumber number a week number, between 1 and 52 or 53, depending on the year, according to the locale
  • obj.localWeekday number a weekday, 1-7, where 1 is the first and 7 is the last day of the week, according to the locale
  • obj.hour number hour of the day, 0-23
  • obj.minute number minute of the hour, 0-59
  • obj.second number second of the minute, 0-59
  • obj.millisecond number millisecond of the second, 0-999
  • opts Object options for creating this DateTime
  • opts.zone string|Zone Optional Default 'local' interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone()
  • opts.locale string Optional Default 'system\'s locale' a locale to set on the resulting DateTime instance
  • opts.outputCalendar string the output calendar to set on the resulting DateTime instance
  • opts.numberingSystem string the numbering system to set on the resulting DateTime instance
  • opts.weekSettings string the week settings to set on the resulting DateTime instance

→ DateTime

{{ $now.constructor.fromObject({ year: 1982, month: 5, day: 25}).toISODate() }}
Result string
"1982-05-25"
{{ $now.constructor.fromObject({ year: 1982 }).toISODate() }}
Result string
"1982-01-01"
{{ $now.constructor.fromObject({ hour: 10, minute: 26, second: 6 }) }}
Result DateTime
"2026-11-26T10:26:06.000Z"

DateTime.fromRFC2822(text, opts = {})

Create a DateTime from an RFC 2822 string

  • text string the RFC 2822 string
  • opts Object options to affect the creation
  • opts.zone string|Zone Optional Default 'local' convert the time to this zone. Since the offset is always specified in the string itself, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
  • opts.setZone boolean Optional Default false override the zone with a fixed-offset zone specified in the string itself, if it specifies one
  • opts.locale string Optional Default 'system's locale' a locale to set on the resulting DateTime instance
  • opts.outputCalendar string the output calendar to set on the resulting DateTime instance
  • opts.numberingSystem string the numbering system to set on the resulting DateTime instance
  • opts.weekSettings string the week settings to set on the resulting DateTime instance

→ DateTime

{{ $now.constructor.fromRFC2822('25 Nov 2016 13:23:12 GMT') }}
Result DateTime
"2016-11-25T13:23:12.000Z"
{{ $now.constructor.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600') }}
Result DateTime
"2016-11-25T07:23:12.000Z"
{{ $now.constructor.fromRFC2822('25 Nov 2016 13:23 Z') }}
Result DateTime
"2016-11-25T13:23:00.000Z"

DateTime.fromSeconds(seconds, options = {})

Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.

  • seconds number a number of seconds since 1970 UTC
  • options Object configuration options for the DateTime
  • options.zone string|Zone Optional Default 'local' the zone to place the DateTime into
  • options.locale string Optional a locale to set on the resulting DateTime instance
  • options.outputCalendar string the output calendar to set on the resulting DateTime instance
  • options.numberingSystem string the numbering system to set on the resulting DateTime instance
  • options.weekSettings string the week settings to set on the resulting DateTime instance

→ DateTime

DateTime.fromSQL(text, opts = {})

Create a DateTime from a SQL date, time, or datetime Defaults to en-US if no locale has been specified, regardless of the system's locale

  • text string the string to parse
  • opts Object options to affect the creation
  • opts.zone string|Zone Optional Default 'local' use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
  • opts.setZone boolean Optional Default false override the zone with a zone specified in the string itself, if it specifies one
  • opts.locale string Optional Default 'en-US' a locale string to use when parsing. Will also set the DateTime to this locale
  • opts.numberingSystem string the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
  • opts.weekSettings string the week settings to set on the resulting DateTime instance
  • opts.outputCalendar string the output calendar to set on the resulting DateTime instance

→ DateTime

{{ $now.constructor.fromSQL('2017-05-15') }}
Result DateTime
"2017-05-15T00:00:00.000Z"
{{ $now.constructor.fromSQL('2017-05-15 09:12:34') }}
Result DateTime
"2017-05-15T09:12:34.000Z"
{{ $now.constructor.fromSQL('2017-05-15 09:12:34.342') }}
Result DateTime
"2017-05-15T09:12:34.342Z"

DateTime.invalid(reason, explanation = null)

Create an invalid DateTime.

  • reason string simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent.
  • explanation string Optional Default null longer explanation, may include parameters and other useful debugging information

→ DateTime

DateTime.isDateTime(o)

Check if an object is an instance of DateTime. Works across context boundaries

  • o object

→ boolean

DateTime.local()

Create a local DateTime

  • year number Optional The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
  • month number Optional Default 1 The month, 1-indexed
  • day number Optional Default 1 The day of the month, 1-indexed
  • hour number Optional Default 0 The hour of the day, in 24-hour time
  • minute number Optional Default 0 The minute of the hour, meaning a number between 0 and 59
  • second number Optional Default 0 The second of the minute, meaning a number between 0 and 59
  • millisecond number Optional Default 0 The millisecond of the second, meaning a number between 0 and 999

→ DateTime

{{ $now }}
Result DateTime
"2026-11-26T14:30:00.000Z"
{{ $now.constructor.local({ zone: "America/New_York" }) }}
Result DateTime
"2026-11-26T09:30:00.000-05:00"
{{ $now.constructor.local(2017) }}
Result DateTime
"2017-01-01T00:00:00.000Z"

DateTime.max(...dateTimes)

Return the max of several date times

  • dateTimes ...DateTime the DateTimes from which to choose the maximum

→ DateTime

DateTime.min(...dateTimes)

Return the min of several date times

  • dateTimes ...DateTime the DateTimes from which to choose the minimum

→ DateTime

DateTime.now()

Create a DateTime for the current instant, in the system's time zone.

Use Settings to override these default values if needed.

→ DateTime

{{ $now.toISO() }}
Result string
"2026-11-26T14:30:00.000Z"

DateTime.parseFormatForOpts(formatOpts, localeOpts = {})

Produce the format string for a set of options

  • formatOpts
  • localeOpts

→ string

DateTime.TIME_24_SIMPLE

DateTime#toLocaleString format like '09:30', always 24-hour.

DateTime.TIME_24_WITH_LONG_OFFSET

DateTime#toLocaleString format like '09:30:23 Eastern Daylight Time', always 24-hour.

DateTime.TIME_24_WITH_SECONDS

DateTime#toLocaleString format like '09:30:23', always 24-hour.

DateTime.TIME_24_WITH_SHORT_OFFSET

DateTime#toLocaleString format like '09:30:23 EDT', always 24-hour.

DateTime.TIME_SIMPLE

DateTime#toLocaleString format like '09:30 AM'. Only 12-hour if the locale is.

DateTime.TIME_WITH_LONG_OFFSET

DateTime#toLocaleString format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.

DateTime.TIME_WITH_SECONDS

DateTime#toLocaleString format like '09:30:23 AM'. Only 12-hour if the locale is.

DateTime.TIME_WITH_SHORT_OFFSET

DateTime#toLocaleString format like '09:30:23 AM EDT'. Only 12-hour if the locale is.

DateTime.utc()

Create a DateTime in UTC

  • year number Optional The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
  • month number Optional Default 1 The month, 1-indexed
  • day number Optional Default 1 The day of the month
  • hour number Optional Default 0 The hour of the day, in 24-hour time
  • minute number Optional Default 0 The minute of the hour, meaning a number between 0 and 59
  • second number Optional Default 0 The second of the minute, meaning a number between 0 and 59
  • millisecond number Optional Default 0 The millisecond of the second, meaning a number between 0 and 999
  • options Object configuration options for the DateTime
  • options.locale string Optional a locale to set on the resulting DateTime instance
  • options.outputCalendar string Optional the output calendar to set on the resulting DateTime instance
  • options.numberingSystem string Optional the numbering system to set on the resulting DateTime instance
  • options.weekSettings string Optional the week settings to set on the resulting DateTime instance

→ DateTime

{{ $now.constructor.utc() }}
Result DateTime
"2026-11-26T14:30:00.000Z"
{{ $now.constructor.utc(2017) }}
Result DateTime
"2017-01-01T00:00:00.000Z"
{{ $now.constructor.utc(2017, 3) }}
Result DateTime
"2017-03-01T00:00:00.000Z"

Read parts

$now.day

Get the day of the month (1-30ish).

{{ $now.constructor.local(2017, 5, 25).day }}
Result number
25

$now.daysInMonth

Returns the number of days in this DateTime's month

{{ $now.constructor.local(2016, 2).daysInMonth }}
Result number
29
{{ $now.constructor.local(2016, 3).daysInMonth }}
Result number
31

$now.daysInYear

Returns the number of days in this DateTime's year

{{ $now.constructor.local(2016).daysInYear }}
Result number
366
{{ $now.constructor.local(2013).daysInYear }}
Result number
365

$now.hour

Get the hour of the day (0-23).

{{ $now.constructor.local(2017, 5, 25, 9).hour }}
Result number
9

$now.invalidExplanation

Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid

{{ $now.invalidExplanation }}
Result null
null

$now.invalidReason

Returns an error code if this DateTime is invalid, or null if the DateTime is valid

{{ $now.invalidReason }}
Result null
null

$now.isInDST

Get whether the DateTime is in a DST.

{{ $now.isInDST }}
Result boolean
false

$now.isInLeapYear

Returns true if this DateTime is in a leap year, false otherwise

{{ $now.constructor.local(2016).isInLeapYear }}
Result boolean
true
{{ $now.constructor.local(2013).isInLeapYear }}
Result boolean
false

$now.isOffsetFixed

Get whether this zone's offset ever changes, as in a DST.

{{ $now.isOffsetFixed }}
Result boolean
true

$now.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
{{ $now.isValid }}
Result boolean
true

$now.isWeekend

Returns true if this date is on a weekend according to the locale, false otherwise

→ boolean

{{ $now.isWeekend }}
Result boolean
false

$now.locale

Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime

{{ $now.locale }}
Result string
"en-US"

$now.localWeekday

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,

→ number

{{ $now.localWeekday }}
Result number
5

$now.localWeekNumber

Get the week number of the week year according to the locale. Different locales assign week numbers differently, because 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.

→ number

{{ $now.localWeekNumber }}
Result number
48

$now.localWeekYear

Get the week year according to the locale. Different locales assign week numbers (and therefor week years) differently, see localWeekNumber.

→ number

{{ $now.localWeekYear }}
Result number
2026

$now.millisecond

Get the millisecond of the second (0-999).

{{ $now.constructor.local(2017, 5, 25, 9, 30, 52, 654).millisecond }}
Result number
654

$now.minute

Get the minute of the hour (0-59).

{{ $now.constructor.local(2017, 5, 25, 9, 30).minute }}
Result number
30

$now.month

Get the month (1-12).

{{ $now.constructor.local(2017, 5, 25).month }}
Result number
5

$now.monthLong

Get the human readable long month name, such as 'October'. Defaults to the system's locale if no locale has been specified

{{ $now.constructor.local(2017, 10, 30).monthLong }}
Result string
"October"

$now.monthShort

Get the human readable short month name, such as 'Oct'. Defaults to the system's locale if no locale has been specified

{{ $now.constructor.local(2017, 10, 30).monthShort }}
Result string
"Oct"

$now.numberingSystem

Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime

{{ $now.numberingSystem }}
Result null
null

$now.offset

Get the UTC offset of this DateTime in minutes

{{ $now.offset }}
Result number
0
{{ $now.constructor.utc().offset }}
Result number
0

$now.offsetNameLong

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

{{ $now.offsetNameLong }}
Result string
"UTC"

$now.offsetNameShort

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

{{ $now.offsetNameShort }}
Result string
"UTC"

$now.ordinal

Get the ordinal (meaning the day of the year)

{{ $now.constructor.local(2017, 5, 25).ordinal }}
Result number
145

$now.outputCalendar

Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime

{{ $now.outputCalendar }}
Result null
null

$now.quarter

Get the quarter

{{ $now.constructor.local(2017, 5, 25).quarter }}
Result number
2

$now.second

Get the second of the minute (0-59).

{{ $now.constructor.local(2017, 5, 25, 9, 30, 52).second }}
Result number
52

$now.weekday

Get the day of the week. 1 is Monday and 7 is Sunday

{{ $now.constructor.local(2014, 11, 31).weekday }}
Result number
null

$now.weekdayLong

Get the human readable long weekday, such as 'Monday'. Defaults to the system's locale if no locale has been specified

{{ $now.constructor.local(2017, 10, 30).weekdayLong }}
Result string
"Monday"

$now.weekdayShort

Get the human readable short weekday, such as 'Mon'. Defaults to the system's locale if no locale has been specified

{{ $now.constructor.local(2017, 10, 30).weekdayShort }}
Result string
"Mon"

$now.weekNumber

Get the week number of the week year (1-52ish).

{{ $now.constructor.local(2017, 5, 25).weekNumber }}
Result number
21

$now.weeksInLocalWeekYear

Returns the number of weeks in this DateTime's local week year

{{ $now.constructor.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear }}
Result number
52
{{ $now.constructor.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear }}
Result number
53

$now.weeksInWeekYear

Returns the number of weeks in this DateTime's year

{{ $now.constructor.local(2004).weeksInWeekYear }}
Result number
53
{{ $now.constructor.local(2013).weeksInWeekYear }}
Result number
52

$now.weekYear

Get the week year

{{ $now.constructor.local(2014, 12, 31).weekYear }}
Result number
2015

$now.year

Get the year

{{ $now.constructor.local(2017, 5, 25).year }}
Result number
2017

$now.zone

Get the time zone associated with this DateTime.

{{ $now.zone }}
Result object
{"fixed":0}

$now.zoneName

Get the name of the time zone.

{{ $now.zoneName }}
Result string
"UTC"

Transform and format

$now.diff(otherDateTime, unit = "milliseconds", opts = {})

Return the difference between two DateTimes as a Duration.

  • otherDateTime DateTime the DateTime to compare this one to
  • unit string|string[] Optional Default ['milliseconds' ] - the unit or array of units (such as 'hours' or 'days') to include in the duration.
  • opts Object options that affect the creation of the Duration
  • opts.conversionAccuracy string Optional Default 'casual' the conversion system to use

→ Duration

$now.diffNow(unit = "milliseconds", opts = {})

Return the difference between this DateTime and right now. See DateTime#diff

  • unit string|string[] Optional Default ['milliseconds' ] - the unit or units units (such as 'hours' or 'days') to include in the duration
  • opts Object options that affect the creation of the Duration
  • opts.conversionAccuracy string Optional Default 'casual' the conversion system to use

→ Duration

$now.endOf(unit, opts)

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

  • unit string The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
  • opts Object options
  • opts.useLocaleWeeks boolean Optional Default false If true, use weeks based on the locale, i.e. use the locale-dependent start of the week

→ DateTime

{{ $now.constructor.local(2014, 3, 3).endOf('month').toISO() }}
Result string
"2014-03-31T23:59:59.999Z"
{{ $now.constructor.local(2014, 3, 3).endOf('year').toISO() }}
Result string
"2014-12-31T23:59:59.999Z"
{{ $now.constructor.local(2014, 3, 3).endOf('week').toISO() }}
Result string
"2014-03-09T23:59:59.999Z"

$now.equals(other)

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.

  • other DateTime the other DateTime

→ boolean

$now.get(unit)

Get the value of unit.

  • unit string a unit such as 'minute' or 'day'

→ number

{{ $now.constructor.local(2017, 7, 4).get('month') }}
Result number
7
{{ $now.constructor.local(2017, 7, 4).get('day') }}
Result number
4

$now.getPossibleOffsets()

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.

→ DateTime[]

{{ $now.getPossibleOffsets() }}
Result list
["2026-11-26T14:30:00.000Z"]

$now.hasSame(otherDateTime, unit, opts)

Return whether this DateTime is in the same unit of time as another DateTime. Higher-order units must also be identical for this function to return true. 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.

  • otherDateTime DateTime the other DateTime
  • unit string the unit of time to check sameness on
  • opts Object options
  • opts.useLocaleWeeks boolean Optional Default false If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; only the locale of this DateTime is used

→ boolean

$now.minus(duration)

Subtract a period of time to this DateTime and return the resulting DateTime See DateTime#plus

  • duration Duration|Object|number The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() @return {DateTime}

$now.plus(duration)

Add a period of time to this DateTime and return the resulting DateTime

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.

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

→ DateTime

{{ $now.plus(123) }}
Result DateTime
"2026-11-26T14:30:00.123Z"
{{ $now.plus({ minutes: 15 }) }}
Result DateTime
"2026-11-26T14:45:00.000Z"
{{ $now.plus({ days: 1 }) }}
Result DateTime
"2026-11-27T14:30:00.000Z"

$now.reconfigure({ locale, numberingSystem, outputCalendar } = {})

"Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.

  • properties Object the properties to set

→ DateTime

{{ $now.constructor.local(2017, 5, 25).reconfigure({ locale: 'en-GB' }) }}
Result DateTime
"2017-05-25T00:00:00.000Z"

$now.resolvedLocaleOptions(opts = {})

Returns the resolved Intl options for this DateTime. This is useful in understanding the behavior of formatting methods

  • opts Object the same options as toLocaleString

→ Object

$now.set(values)

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

  • values Object a mapping of units to numbers

→ DateTime

$now.setLocale(locale)

"Set" the locale. Returns a newly-constructed DateTime. Just a convenient alias for reconfigure({ locale })

→ DateTime

{{ $now.constructor.local(2017, 5, 25).setLocale('en-GB') }}
Result DateTime
"2017-05-25T00:00:00.000Z"

$now.setZone(zone, { keepLocalTime = false, keepCalendarTime = false } = {})

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

  • zone string|Zone Optional Default 'local' 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 `DateTime#Zone` class.
  • opts Object options
  • opts.keepLocalTime boolean Optional Default false If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this.

→ DateTime

$now.startOf(unit, { useLocaleWeeks = false } = {})

"Set" this DateTime to the beginning of a unit of time.

  • unit string The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
  • opts Object options
  • opts.useLocaleWeeks boolean Optional Default false If true, use weeks based on the locale, i.e. use the locale-dependent start of the week

→ DateTime

{{ $now.constructor.local(2014, 3, 3).startOf('month').toISODate() }}
Result string
"2014-03-01"
{{ $now.constructor.local(2014, 3, 3).startOf('year').toISODate() }}
Result string
"2014-01-01"
{{ $now.constructor.local(2014, 3, 3).startOf('week').toISODate() }}
Result string
"2014-03-03"

$now.toBSON()

Returns a BSON serializable equivalent to this DateTime.

→ Date

{{ $now.toBSON() }}
Result object
"2026-11-26T14:30:00.000Z"

$now.toFormat(fmt, opts = {})

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.

  • fmt string the format string
  • opts Object opts to override the configuration options on this DateTime

→ string

{{ $now.toFormat('yyyy LLL dd') }}
Result string
"2026 Nov 26"
{{ $now.setLocale('fr').toFormat('yyyy LLL dd') }}
Result string
"2026 nov. 26"
{{ $now.toFormat('yyyy LLL dd', { locale: "fr" }) }}
Result string
"2026 nov. 26"

$now.toHTTP()

Returns a string representation of this DateTime appropriate for use in HTTP headers. The output is always expressed in GMT. Specifically, the string conforms to RFC 1123.

→ string

{{ $now.constructor.utc(2014, 7, 13).toHTTP() }}
Result string
"Sun, 13 Jul 2014 00:00:00 GMT"
{{ $now.constructor.utc(2014, 7, 13, 19).toHTTP() }}
Result string
"Sun, 13 Jul 2014 19:00:00 GMT"

$now.toISO({ format = "extended", suppressSeconds = false, suppressMilliseconds = false, includeOffset = true, extendedZone = false, precision = "milliseconds", } = {})

Returns an ISO 8601-compliant string representation of this DateTime

  • opts Object options
  • opts.suppressMilliseconds boolean Optional Default false exclude milliseconds from the format if they're 0
  • opts.suppressSeconds boolean Optional Default false exclude seconds from the format if they're 0
  • opts.includeOffset boolean Optional Default true include the offset, such as 'Z' or '-04:00'
  • opts.extendedZone boolean Optional Default false add the time zone format extension
  • opts.format string Optional Default 'extended' choose between the basic and extended format
  • opts.precision string Optional Default 'milliseconds' truncate output to desired presicion: 'years', 'months', 'days', 'hours', 'minutes', 'seconds' or 'milliseconds'. When precision and suppressSeconds or suppressMilliseconds are used together, precision sets the maximum unit shown in the output, however seconds or milliseconds will still be suppressed if they are 0.

→ string|null

{{ $now.constructor.utc(1983, 5, 25).toISO() }}
Result string
"1983-05-25T00:00:00.000Z"
{{ $now.toISO() }}
Result string
"2026-11-26T14:30:00.000Z"
{{ $now.toISO({ includeOffset: false }) }}
Result string
"2026-11-26T14:30:00.000"

$now.toISODate({ format = "extended", precision = "day" } = {})

Returns an ISO 8601-compliant string representation of this DateTime's date component

  • opts Object options
  • opts.format string Optional Default 'extended' choose between the basic and extended format
  • opts.precision string Optional Default 'day' truncate output to desired precision: 'years', 'months', or 'days'.

→ string|null

{{ $now.constructor.utc(1982, 5, 25).toISODate() }}
Result string
"1982-05-25"
{{ $now.constructor.utc(1982, 5, 25).toISODate({ format: 'basic' }) }}
Result string
"19820525"
{{ $now.constructor.utc(1982, 5, 25).toISODate({ precision: 'month' }) }}
Result string
"1982-05"

$now.toISOTime({ suppressMilliseconds = false, suppressSeconds = false, includeOffset = true, includePrefix = false, extendedZone = false, format = "extended", precision = "milliseconds", } = {})

Returns an ISO 8601-compliant string representation of this DateTime's time component

  • opts Object options
  • opts.suppressMilliseconds boolean Optional Default false exclude milliseconds from the format if they're 0
  • opts.suppressSeconds boolean Optional Default false exclude seconds from the format if they're 0
  • opts.includeOffset boolean Optional Default true include the offset, such as 'Z' or '-04:00'
  • opts.extendedZone boolean Optional Default true add the time zone format extension
  • opts.includePrefix boolean Optional Default false include the `T` prefix
  • opts.format string Optional Default 'extended' choose between the basic and extended format
  • opts.precision string Optional Default 'milliseconds' truncate output to desired presicion: 'hours', 'minutes', 'seconds' or 'milliseconds'. When precision and suppressSeconds or suppressMilliseconds are used together, precision sets the maximum unit shown in the output, however seconds or milliseconds will still be suppressed if they are 0.

→ string

{{ $now.constructor.utc().set({ hour: 7, minute: 34 }).toISOTime() }}
Result string
"07:34:00.000Z"
{{ $now.constructor.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) }}
Result string
"07:34Z"
{{ $now.constructor.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) }}
Result string
"073400.000Z"

$now.toISOWeekDate()

Returns an ISO 8601-compliant string representation of this DateTime's week date

→ string

{{ $now.constructor.utc(1982, 5, 25).toISOWeekDate() }}
Result string
"1982-W21-2"

$now.toJSDate()

Returns a JavaScript Date equivalent to this DateTime.

→ Date

{{ $now.toJSDate() }}
Result object
"2026-11-26T14:30:00.000Z"

$now.toJSON()

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

→ string

{{ $now.toJSON() }}
Result string
"2026-11-26T14:30:00.000Z"

$now.toLocal()

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

Equivalent to setZone('local')

→ DateTime

{{ $now.toLocal() }}
Result DateTime
"2026-11-26T14:30:00.000Z"

$now.toLocaleParts(opts = {})

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

  • opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`.
{{ $now.toLocaleParts() }}
Result list
[
  {
    "type": "month",
    "value": "11"
  },
  {
    "type": "literal",
    "value": "/"
  },
  {
    "type": "day",
    "value": "26"
  },
  {
    "type": "literal",
    "value": "/"
  },
  {
    "type": "year",
    "value": "2026"
  }
]

$now.toLocaleString(formatOpts = Formats.DATE_SHORT, opts = {})

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. The exact behavior of this method is browser-specific, but in general it will return an appropriate representation of the DateTime in the assigned locale. Defaults to the system's locale if no locale has been specified

  • formatOpts {Object} - Intl.DateTimeFormat constructor options and configuration options
  • opts Object opts to override the configuration options on this DateTime

→ string

{{ $now.toLocaleString() }}
Result string
"11/26/2026"
{{ $now.setLocale('en-gb').toLocaleString() }}
Result string
"26/11/2026"
{{ $now.toLocaleString($now.constructor.DATE_FULL) }}
Result string
"November 26, 2026"

$now.toMillis()

Returns the epoch milliseconds of this DateTime.

→ number

{{ $now.toMillis() }}
Result number
1795703400000

$now.toObject(opts = {})

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

  • opts - options for generating the object
  • opts.includeConfig boolean Optional Default false include configuration attributes in the output

→ Object

{{ $now.toObject() }}
Result object
{
  "year": 2026,
  "month": 11,
  "day": 26,
  "hour": 14,
  "minute": 30,
  "second": 0,
  "millisecond": 0
}

$now.toRelative(options = {})

Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your platform supports Intl.RelativeTimeFormat. Rounds towards zero by default.

  • options Object options that affect the output
  • options.base DateTime Optional Default DateTime.now() the DateTime to use as the basis to which this time is compared. Defaults to now.
  • options.style string Optional Default "long" the style of units, must be "long", "short", or "narrow"
  • options.unit string|string[] use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
  • options.round boolean Optional Default true whether to round the numbers in the output.
  • options.rounding string Optional Default "trunc" rounding method to use when rounding the numbers in the output. Can be "trunc" (toward zero), "expand" (away from zero), "round", "floor", or "ceil".
  • options.padding number Optional Default 0 padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
  • options.locale string override the locale of this DateTime
  • options.numberingSystem string override the numberingSystem of this DateTime. The Intl system may choose not to honor this
{{ $now.plus({ days: 1 }).toRelative() }}
Result string
"in 1 day"
{{ $now.setLocale("es").toRelative({ days: 1 }) }}
Result string
"dentro de 0 segundos"
{{ $now.plus({ days: 1 }).toRelative({ locale: "fr" }) }}
Result string
"dans 1 jour"

$now.toRelativeCalendar(options = {})

Returns a string representation of this date relative to today, such as "yesterday" or "next month". Only internationalizes on platforms that supports Intl.RelativeTimeFormat.

  • options Object options that affect the output
  • options.base DateTime Optional Default DateTime.now() the DateTime to use as the basis to which this time is compared. Defaults to now.
  • options.locale string override the locale of this DateTime
  • options.unit string use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days"
  • options.numberingSystem string override the numberingSystem of this DateTime. The Intl system may choose not to honor this
{{ $now.plus({ days: 1 }).toRelativeCalendar() }}
Result string
"tomorrow"
{{ $now.setLocale("es").plus({ days: 1 }).toRelative() }}
Result string
"dentro de 1 día"
{{ $now.plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) }}
Result string
"demain"

$now.toRFC2822()

Returns an RFC 2822-compatible string representation of this DateTime

→ string

{{ $now.constructor.utc(2014, 7, 13).toRFC2822() }}
Result string
"Sun, 13 Jul 2014 00:00:00 +0000"
{{ $now.constructor.local(2014, 7, 13).toRFC2822() }}
Result string
"Sun, 13 Jul 2014 00:00:00 +0000"

$now.toSeconds()

Returns the epoch seconds (including milliseconds in the fractional part) of this DateTime.

→ number

{{ $now.toSeconds() }}
Result number
1795703400

$now.toSQL(opts = {})

Returns a string representation of this DateTime appropriate for use in SQL DateTime

  • opts Object options
  • opts.includeZone boolean Optional Default false include the zone, such as 'America/New_York'. Overrides includeOffset.
  • opts.includeOffset boolean Optional Default true include the offset, such as 'Z' or '-04:00'
  • opts.includeOffsetSpace boolean Optional Default true include the space between the time and the offset, such as '05:15:16.345 -04:00'

→ string

{{ $now.constructor.utc(2014, 7, 13).toSQL() }}
Result string
"2014-07-13 00:00:00.000 Z"
{{ $now.constructor.local(2014, 7, 13).toSQL() }}
Result string
"2014-07-13 00:00:00.000 Z"
{{ $now.constructor.local(2014, 7, 13).toSQL({ includeOffset: false }) }}
Result string
"2014-07-13 00:00:00.000"

$now.toSQLDate()

Returns a string representation of this DateTime appropriate for use in SQL Date

→ string|null

{{ $now.constructor.utc(2014, 7, 13).toSQLDate() }}
Result string
"2014-07-13"

$now.toSQLTime({ includeOffset = true, includeZone = false, includeOffsetSpace = true } = {})

Returns a string representation of this DateTime appropriate for use in SQL Time

  • opts Object options
  • opts.includeZone boolean Optional Default false include the zone, such as 'America/New_York'. Overrides includeOffset.
  • opts.includeOffset boolean Optional Default true include the offset, such as 'Z' or '-04:00'
  • opts.includeOffsetSpace boolean Optional Default true include the space between the time and the offset, such as '05:15:16.345 -04:00'

→ string

{{ $now.constructor.utc().toSQL() }}
Result string
"2026-11-26 14:30:00.000 Z"
{{ $now.toSQL() }}
Result string
"2026-11-26 14:30:00.000 Z"
{{ $now.toSQL({ includeOffset: false }) }}
Result string
"2026-11-26 14:30:00.000"

$now.toString()

Returns a string representation of this DateTime appropriate for debugging

→ string

{{ $now.toString() }}
Result string
"2026-11-26T14:30:00.000Z"

$now.toUnixInteger()

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

→ number

{{ $now.toUnixInteger() }}
Result number
1795703400

$now.toUTC(offset = 0, opts = {})

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

Equivalent to DateTime#setZone('utc')

  • offset number Optional Default 0 optionally, an offset from UTC in minutes
  • opts Object Optional Default {} options to pass to `setZone()`

→ DateTime

{{ $now.toUTC() }}
Result DateTime
"2026-11-26T14:30:00.000Z"

$now.until(otherDateTime)

Return an Interval spanning between this DateTime and another DateTime

  • otherDateTime DateTime the other end point of the Interval

→ Interval|DateTime

$now.valueOf()

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

→ number

{{ $now.valueOf() }}
Result number
1795703400000

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs