Luxon dates
Dates and times with Luxon: $now and $today are Luxon DateTime values, so every method below works on them.
$now uses the server time zone: set the zone you need before formatting.
{{ $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.
-
fmtString the format the string is expected to be in (see description) -
optionsObject 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.
-
textstring the string to parse -
fmtstring the format the string is expected to be in (see the link below for the formats) -
optsObject options to affect the creation -
opts.zonestring|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.setZoneboolean Optional Defaultfalseoverride the zone with a zone specified in the string itself, if it specifies one -
opts.localestring Optional Default'en-US'a locale string to use when parsing. Will also set the DateTime to this locale -
opts.numberingSystemstring the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system -
opts.weekSettingsstring the week settings to set on the resulting DateTime instance -
opts.outputCalendarstring 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()
-
textstring the string to parse -
fmtstring the format the string is expected to be in (see description) -
optionsObject 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.
-
textString the string to parse -
formatParserTokenParser parser from `DateTime.buildFormatParser` -
optsObject options taken by fromFormat()
→ DateTime
DateTime.fromHTTP(text, opts = {})
Create a DateTime from an HTTP header date
-
textstring the HTTP header date -
optsObject options to affect the creation -
opts.zonestring|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.setZoneboolean Optional Defaultfalseoverride 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.localestring Optional Default'system's locale'a locale to set on the resulting DateTime instance -
opts.outputCalendarstring the output calendar to set on the resulting DateTime instance -
opts.numberingSystemstring the numbering system to set on the resulting DateTime instance -
opts.weekSettingsstring the week settings to set on the resulting DateTime instance
→ DateTime
DateTime.fromISO(text, opts = {})
Create a DateTime from an ISO 8601 string
-
textstring the ISO string -
optsObject options to affect the creation -
opts.zonestring|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.setZoneboolean Optional Defaultfalseoverride the zone with a fixed-offset zone specified in the string itself, if it specifies one -
opts.localestring Optional Default'system's locale'a locale to set on the resulting DateTime instance -
opts.outputCalendarstring Optional the output calendar to set on the resulting DateTime instance -
opts.numberingSystemstring Optional the numbering system to set on the resulting DateTime instance -
opts.weekSettingsstring Optional the week settings to set on the resulting DateTime instance
→ DateTime
DateTime.fromJSDate(date, options = {})
Create a DateTime from a JavaScript Date object. Uses the default zone.
-
dateDate a JavaScript Date object -
optionsObject configuration options for the DateTime -
options.zonestring|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.
-
millisecondsnumber a number of milliseconds since 1970 UTC -
optionsObject configuration options for the DateTime -
options.zonestring|Zone Optional Default'local'the zone to place the DateTime into -
options.localestring Optional a locale to set on the resulting DateTime instance -
options.outputCalendarstring the output calendar to set on the resulting DateTime instance -
options.numberingSystemstring the numbering system to set on the resulting DateTime instance -
options.weekSettingsstring 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.
-
objObject the object to create the DateTime from -
obj.yearnumber a year, such as 1987 -
obj.monthnumber a month, 1-12 -
obj.daynumber a day of the month, 1-31, depending on the month -
obj.ordinalnumber day of the year, 1-365 or 366 -
obj.weekYearnumber an ISO week year -
obj.weekNumbernumber an ISO week number, between 1 and 52 or 53, depending on the year -
obj.weekdaynumber an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday -
obj.localWeekYearnumber a week year, according to the locale -
obj.localWeekNumbernumber a week number, between 1 and 52 or 53, depending on the year, according to the locale -
obj.localWeekdaynumber a weekday, 1-7, where 1 is the first and 7 is the last day of the week, according to the locale -
obj.hournumber hour of the day, 0-23 -
obj.minutenumber minute of the hour, 0-59 -
obj.secondnumber second of the minute, 0-59 -
obj.millisecondnumber millisecond of the second, 0-999 -
optsObject options for creating this DateTime -
opts.zonestring|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.localestring Optional Default'system\'s locale'a locale to set on the resulting DateTime instance -
opts.outputCalendarstring the output calendar to set on the resulting DateTime instance -
opts.numberingSystemstring the numbering system to set on the resulting DateTime instance -
opts.weekSettingsstring the week settings to set on the resulting DateTime instance
→ DateTime
DateTime.fromRFC2822(text, opts = {})
Create a DateTime from an RFC 2822 string
-
textstring the RFC 2822 string -
optsObject options to affect the creation -
opts.zonestring|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.setZoneboolean Optional Defaultfalseoverride the zone with a fixed-offset zone specified in the string itself, if it specifies one -
opts.localestring Optional Default'system's locale'a locale to set on the resulting DateTime instance -
opts.outputCalendarstring the output calendar to set on the resulting DateTime instance -
opts.numberingSystemstring the numbering system to set on the resulting DateTime instance -
opts.weekSettingsstring the week settings to set on the resulting DateTime instance
→ DateTime
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.
-
secondsnumber a number of seconds since 1970 UTC -
optionsObject configuration options for the DateTime -
options.zonestring|Zone Optional Default'local'the zone to place the DateTime into -
options.localestring Optional a locale to set on the resulting DateTime instance -
options.outputCalendarstring the output calendar to set on the resulting DateTime instance -
options.numberingSystemstring the numbering system to set on the resulting DateTime instance -
options.weekSettingsstring 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
-
textstring the string to parse -
optsObject options to affect the creation -
opts.zonestring|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.setZoneboolean Optional Defaultfalseoverride the zone with a zone specified in the string itself, if it specifies one -
opts.localestring Optional Default'en-US'a locale string to use when parsing. Will also set the DateTime to this locale -
opts.numberingSystemstring the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system -
opts.weekSettingsstring the week settings to set on the resulting DateTime instance -
opts.outputCalendarstring the output calendar to set on the resulting DateTime instance
→ DateTime
DateTime.invalid(reason, explanation = null)
Create an invalid DateTime.
-
reasonstring simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent. -
explanationstring Optional Defaultnulllonger 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
-
oobject
→ boolean
DateTime.local()
Create a local DateTime
-
yearnumber Optional The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used -
monthnumber Optional Default1The month, 1-indexed -
daynumber Optional Default1The day of the month, 1-indexed -
hournumber Optional Default0The hour of the day, in 24-hour time -
minutenumber Optional Default0The minute of the hour, meaning a number between 0 and 59 -
secondnumber Optional Default0The second of the minute, meaning a number between 0 and 59 -
millisecondnumber Optional Default0The millisecond of the second, meaning a number between 0 and 999
→ DateTime
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
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
-
yearnumber Optional The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used -
monthnumber Optional Default1The month, 1-indexed -
daynumber Optional Default1The day of the month -
hournumber Optional Default0The hour of the day, in 24-hour time -
minutenumber Optional Default0The minute of the hour, meaning a number between 0 and 59 -
secondnumber Optional Default0The second of the minute, meaning a number between 0 and 59 -
millisecondnumber Optional Default0The millisecond of the second, meaning a number between 0 and 999 -
optionsObject configuration options for the DateTime -
options.localestring Optional a locale to set on the resulting DateTime instance -
options.outputCalendarstring Optional the output calendar to set on the resulting DateTime instance -
options.numberingSystemstring Optional the numbering system to set on the resulting DateTime instance -
options.weekSettingsstring Optional the week settings to set on the resulting DateTime instance
→ DateTime
Read parts
$now.day
Get the day of the month (1-30ish).
$now.daysInMonth
Returns the number of days in this DateTime's month
$now.daysInYear
Returns the number of days in this DateTime's year
$now.hour
Get the hour of the day (0-23).
$now.invalidExplanation
Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
$now.invalidReason
Returns an error code if this DateTime is invalid, or null if the DateTime is valid
$now.isInDST
Get whether the DateTime is in a DST.
$now.isInLeapYear
Returns true if this DateTime is in a leap year, false otherwise
$now.isOffsetFixed
Get whether this zone's offset ever changes, as in a DST.
$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.isWeekend
Returns true if this date is on a weekend according to the locale, false otherwise
→ boolean
$now.locale
Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime
$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.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.localWeekYear
Get the week year according to the locale. Different locales assign week numbers (and therefor week years) differently, see localWeekNumber.
→ number
$now.millisecond
Get the millisecond of the second (0-999).
$now.minute
Get the minute of the hour (0-59).
$now.month
Get the month (1-12).
$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.monthShort
Get the human readable short month name, such as 'Oct'. Defaults to the system's locale if no locale has been specified
$now.numberingSystem
Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime
$now.offset
Get the UTC offset of this DateTime in minutes
$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.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.ordinal
Get the ordinal (meaning the day of the year)
$now.outputCalendar
Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime
$now.quarter
Get the quarter
$now.second
Get the second of the minute (0-59).
$now.weekday
Get the day of the week. 1 is Monday and 7 is Sunday
$now.weekdayLong
Get the human readable long weekday, such as 'Monday'. Defaults to the system's locale if no locale has been specified
$now.weekdayShort
Get the human readable short weekday, such as 'Mon'. Defaults to the system's locale if no locale has been specified
$now.weekNumber
Get the week number of the week year (1-52ish).
$now.weeksInLocalWeekYear
Returns the number of weeks in this DateTime's local week year
$now.weeksInWeekYear
Returns the number of weeks in this DateTime's year
$now.weekYear
Get the week year
$now.year
Get the year
$now.zone
Get the time zone associated with this DateTime.
$now.zoneName
Get the name of the time zone.
Transform and format
$now.diff(otherDateTime, unit = "milliseconds", opts = {})
Return the difference between two DateTimes as a Duration.
-
otherDateTimeDateTime the DateTime to compare this one to -
unitstring|string[] Optional Default['milliseconds'] - the unit or array of units (such as 'hours' or 'days') to include in the duration. -
optsObject options that affect the creation of the Duration -
opts.conversionAccuracystring 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
-
unitstring|string[] Optional Default['milliseconds'] - the unit or units units (such as 'hours' or 'days') to include in the duration -
optsObject options that affect the creation of the Duration -
opts.conversionAccuracystring 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
-
unitstring The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'. -
optsObject options -
opts.useLocaleWeeksboolean Optional DefaultfalseIf true, use weeks based on the locale, i.e. use the locale-dependent start of the week
→ DateTime
$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.
-
otherDateTime the other DateTime
→ boolean
$now.get(unit)
Get the value of unit.
-
unitstring a unit such as 'minute' or 'day'
→ number
$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.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.
-
otherDateTimeDateTime the other DateTime -
unitstring the unit of time to check sameness on -
optsObject options -
opts.useLocaleWeeksboolean Optional DefaultfalseIf 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
-
durationDuration|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.
-
durationDuration|Object|number The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
→ DateTime
$now.reconfigure({ locale, numberingSystem, outputCalendar } = {})
"Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
-
propertiesObject the properties to set
→ DateTime
$now.resolvedLocaleOptions(opts = {})
Returns the resolved Intl options for this DateTime. This is useful in understanding the behavior of formatting methods
-
optsObject 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.
-
valuesObject 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.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.
-
zonestring|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. -
optsObject options -
opts.keepLocalTimeboolean Optional DefaultfalseIf 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.
-
unitstring The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'. -
optsObject options -
opts.useLocaleWeeksboolean Optional DefaultfalseIf true, use weeks based on the locale, i.e. use the locale-dependent start of the week
→ DateTime
$now.toBSON()
Returns a BSON serializable equivalent to this DateTime.
→ Date
$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.
-
fmtstring the format string -
optsObject opts to override the configuration options on this DateTime
→ string
$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.toISO({ format = "extended", suppressSeconds = false, suppressMilliseconds = false, includeOffset = true, extendedZone = false, precision = "milliseconds", } = {})
Returns an ISO 8601-compliant string representation of this DateTime
-
optsObject options -
opts.suppressMillisecondsboolean Optional Defaultfalseexclude milliseconds from the format if they're 0 -
opts.suppressSecondsboolean Optional Defaultfalseexclude seconds from the format if they're 0 -
opts.includeOffsetboolean Optional Defaulttrueinclude the offset, such as 'Z' or '-04:00' -
opts.extendedZoneboolean Optional Defaultfalseadd the time zone format extension -
opts.formatstring Optional Default'extended'choose between the basic and extended format -
opts.precisionstring 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.toISODate({ format = "extended", precision = "day" } = {})
Returns an ISO 8601-compliant string representation of this DateTime's date component
-
optsObject options -
opts.formatstring Optional Default'extended'choose between the basic and extended format -
opts.precisionstring Optional Default'day'truncate output to desired precision: 'years', 'months', or 'days'.
→ string|null
$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
-
optsObject options -
opts.suppressMillisecondsboolean Optional Defaultfalseexclude milliseconds from the format if they're 0 -
opts.suppressSecondsboolean Optional Defaultfalseexclude seconds from the format if they're 0 -
opts.includeOffsetboolean Optional Defaulttrueinclude the offset, such as 'Z' or '-04:00' -
opts.extendedZoneboolean Optional Defaulttrueadd the time zone format extension -
opts.includePrefixboolean Optional Defaultfalseinclude the `T` prefix -
opts.formatstring Optional Default'extended'choose between the basic and extended format -
opts.precisionstring 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.toISOWeekDate()
Returns an ISO 8601-compliant string representation of this DateTime's week date
→ string
$now.toJSDate()
Returns a JavaScript Date equivalent to this DateTime.
→ Date
$now.toJSON()
Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.
→ string
$now.toLocal()
"Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.
Equivalent to setZone('local')
→ DateTime
$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.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 -
optsObject opts to override the configuration options on this DateTime
→ string
$now.toMillis()
Returns the epoch milliseconds of this DateTime.
→ number
$now.toObject(opts = {})
Returns a JavaScript object with this DateTime's year, month, day, and so on.
-
opts - options for generating the object -
opts.includeConfigboolean Optional Defaultfalseinclude configuration attributes in the output
→ Object
$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.
-
optionsObject options that affect the output -
options.baseDateTime Optional DefaultDateTime.now()the DateTime to use as the basis to which this time is compared. Defaults to now. -
options.stylestring Optional Default"long"the style of units, must be "long", "short", or "narrow" -
options.unitstring|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.roundboolean Optional Defaulttruewhether to round the numbers in the output. -
options.roundingstring 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.paddingnumber Optional Default0padding 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.localestring override the locale of this DateTime -
options.numberingSystemstring override the numberingSystem of this DateTime. The Intl system may choose not to honor this
$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.
-
optionsObject options that affect the output -
options.baseDateTime Optional DefaultDateTime.now()the DateTime to use as the basis to which this time is compared. Defaults to now. -
options.localestring override the locale of this DateTime -
options.unitstring use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days" -
options.numberingSystemstring override the numberingSystem of this DateTime. The Intl system may choose not to honor this
$now.toRFC2822()
Returns an RFC 2822-compatible string representation of this DateTime
→ string
$now.toSeconds()
Returns the epoch seconds (including milliseconds in the fractional part) of this DateTime.
→ number
$now.toSQL(opts = {})
Returns a string representation of this DateTime appropriate for use in SQL DateTime
-
optsObject options -
opts.includeZoneboolean Optional Defaultfalseinclude the zone, such as 'America/New_York'. Overrides includeOffset. -
opts.includeOffsetboolean Optional Defaulttrueinclude the offset, such as 'Z' or '-04:00' -
opts.includeOffsetSpaceboolean Optional Defaulttrueinclude the space between the time and the offset, such as '05:15:16.345 -04:00'
→ string
$now.toSQLDate()
Returns a string representation of this DateTime appropriate for use in SQL Date
→ string|null
$now.toSQLTime({ includeOffset = true, includeZone = false, includeOffsetSpace = true } = {})
Returns a string representation of this DateTime appropriate for use in SQL Time
-
optsObject options -
opts.includeZoneboolean Optional Defaultfalseinclude the zone, such as 'America/New_York'. Overrides includeOffset. -
opts.includeOffsetboolean Optional Defaulttrueinclude the offset, such as 'Z' or '-04:00' -
opts.includeOffsetSpaceboolean Optional Defaulttrueinclude the space between the time and the offset, such as '05:15:16.345 -04:00'
→ string
$now.toString()
Returns a string representation of this DateTime appropriate for debugging
→ string
$now.toUnixInteger()
Returns the epoch seconds (as a whole number) of this DateTime.
→ number
$now.toUTC(offset = 0, opts = {})
"Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
Equivalent to DateTime#setZone('utc')
-
offsetnumber Optional Default0optionally, an offset from UTC in minutes -
optsObject Optional Default{}options to pass to `setZone()`
→ DateTime
$now.until(otherDateTime)
Return an Interval spanning between this DateTime and another DateTime
-
otherDateTimeDateTime the other end point of the Interval
→ Interval|DateTime
$now.valueOf()
Returns the epoch milliseconds of this DateTime. Alias of DateTime#toMillis
→ number