luxon

2.0.2

DateTime

A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.

A DateTime comprises of:

  • A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
  • A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone).
  • Configuration properties that effect how output strings are formatted, such as locale, numberingSystem, and outputCalendar.

Here is a brief overview of the most commonly used functionality it provides:

DateTime#day, DateTime#hour, DateTime#minute, DateTime#second, DateTime#millisecond accessors.

There's plenty others documented below. In addition, for more information on subtler topics like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.

new DateTime(config: any)
Parameters
config (any)
Static Members
now()
local(year?, month, day, hour, minute, second, millisecond)
utc(year?, month, day, hour, minute, second, millisecond, options)
fromJSDate(date, options)
fromMillis(milliseconds, options)
fromSeconds(seconds, options)
fromObject(obj, opts)
fromISO(text, opts)
fromRFC2822(text, opts)
fromHTTP(text, opts)
fromFormat(text, fmt, opts)
fromString(text, fmt, opts)
fromSQL(text, opts)
invalid(reason, explanation)
isDateTime(o)
min(dateTimes)
max(dateTimes)
fromFormatExplain(text, fmt, options)
fromStringExplain(text, fmt, options)
DATE_SHORT
DATE_MED
DATE_MED_WITH_WEEKDAY
DATE_FULL
DATE_HUGE
TIME_SIMPLE
TIME_WITH_SECONDS
TIME_WITH_SHORT_OFFSET
TIME_WITH_LONG_OFFSET
TIME_24_SIMPLE
TIME_24_WITH_SECONDS
TIME_24_WITH_SHORT_OFFSET
TIME_24_WITH_LONG_OFFSET
DATETIME_SHORT
DATETIME_SHORT_WITH_SECONDS
DATETIME_MED
DATETIME_MED_WITH_SECONDS
DATETIME_MED_WITH_WEEKDAY
DATETIME_FULL
DATETIME_FULL_WITH_SECONDS
DATETIME_HUGE
DATETIME_HUGE_WITH_SECONDS
Instance Members
get(unit)
isValid
invalidReason
invalidExplanation
locale
numberingSystem
outputCalendar
zone
zoneName
year
quarter
month
day
hour
minute
second
millisecond
weekYear
weekNumber
weekday
ordinal
monthShort
monthLong
weekdayShort
weekdayLong
offset
offsetNameShort
offsetNameLong
isOffsetFixed
isInDST
isInLeapYear
daysInMonth
daysInYear
weeksInWeekYear
resolvedLocaleOptions(opts)
toUTC(offset, opts)
toLocal()
setZone(zone, opts)
reconfigure(properties)
setLocale(locale)
set(values)
plus(duration)
minus(duration)
startOf(unit)
endOf(unit)
toFormat(fmt, opts)
toLocaleString(formatOpts, opts)
toLocaleParts(opts)
toISO(opts)
toISODate(opts)
toISOWeekDate()
toISOTime(opts)
toRFC2822()
toHTTP()
toSQLDate()
toSQLTime(opts)
toSQL(opts)
toString()
valueOf()
toMillis()
toSeconds()
toJSON()
toBSON()
toObject(opts)
toJSDate()
diff(otherDateTime, unit, opts)
diffNow(unit, opts)
until(otherDateTime)
hasSame(otherDateTime, unit)
equals(other)
toRelative(options)
toRelativeCalendar(options)

Duration

A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use DateTime.plus to add a Duration object to a DateTime, producing another DateTime.

Here is a brief overview of commonly used methods and getters in Duration:

There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.

new Duration(config: any)
Parameters
config (any)
Static Members
fromMillis(count, opts)
fromObject(obj, opts)
fromISO(text, opts)
fromISOTime(text, opts)
invalid(reason, explanation)
isDuration(o)
Instance Members
locale
numberingSystem
toFormat(fmt, opts)
toObject()
toISO()
toISOTime(opts)
toJSON()
toString()
toMillis()
valueOf()
plus(duration)
minus(duration)
mapUnits(fn)
get(unit)
set(values)
reconfigure($0)
as(unit)
normalize()
shiftTo(units)
negate()
years
quarters
months
weeks
days
hours
minutes
seconds
milliseconds
isValid
invalidReason
invalidExplanation
equals(other)

Interval

An Interval object represents a half-open interval of time, where each endpoint is a DateTime. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them.

Here is a brief overview of the most commonly used methods and getters in Interval:

new Interval(config: any)
Parameters
config (any)
Static Members
invalid(reason, explanation)
fromDateTimes(start, end)
after(start, duration)
before(end, duration)
fromISO(text, opts?)
isInterval(o)
merge(intervals)
xor(intervals)
Instance Members
start
end
isValid
invalidReason
invalidExplanation
length(unit)
count(unit)
hasSame(unit)
isEmpty()
isAfter(dateTime)
isBefore(dateTime)
contains(dateTime)
set(values)
splitAt(dateTimes)
splitBy(duration)
divideEqually(numberOfParts)
overlaps(other)
abutsStart(other)
abutsEnd(other)
engulfs(other)
equals(other)
intersection(other)
union(other)
difference(intervals)
toString()
toISO(opts)
toISODate()
toISOTime(opts)
toFormat(dateFormat, opts)
toDuration(unit, opts)
mapEndpoints(mapFn)

Info

The Info class contains static methods for retrieving general time and date related data. For example, it has methods for finding out if a time zone has a DST, for listing the months in any supported locale, and for discovering which of Luxon features are available in the current environment.

new Info()
Static Members
hasDST(zone)
isValidIANAZone(zone)
normalizeZone(input?)
months(length, opts)
monthsFormat(length, opts)
weekdays(length, opts)
weekdaysFormat(length, opts)
meridiems(opts)
eras(length, opts)
features()

Zone

Zone
Instance Members
type
name
isUniversal
offsetName(ts, opts)
formatOffset(ts, format)
offset(ts)
equals(otherZone)
isValid

FixedOffsetZone

A zone with a fixed offset (meaning no DST)

new FixedOffsetZone(offset: any)

Extends Zone

Parameters
offset (any)
Static Members
utcInstance
instance(offset)
parseSpecifier(s)
Instance Members
type
name
offsetName()
formatOffset(ts, format)
isUniversal
offset()
equals(otherZone)
isValid

IANAZone

A zone identified by an IANA identifier, like America/New_York

new IANAZone(name: any)

Extends Zone

Parameters
name (any)
Static Members
create(name)
resetCache()
isValidSpecifier(s)
isValidZone(zone)
Instance Members
type
name
isUniversal
offsetName(ts, $1)
formatOffset(ts, format)
offset(ts)
equals(otherZone)
isValid

InvalidZone

A zone that failed to parse. You should never need to instantiate this.

new InvalidZone(zoneName: any)

Extends Zone

Parameters
zoneName (any)
Instance Members
type
name
isUniversal
offsetName()
formatOffset()
offset()
equals()
isValid

SystemZone

Represents the local zone for this JavaScript environment.

new SystemZone()

Extends Zone

Static Members
instance
Instance Members
type
name
isUniversal
offsetName(ts, $1)
formatOffset(ts, format)
offset(ts)
equals(otherZone)
isValid

Settings

Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here.

new Settings()
Static Members
now
now
defaultZone
defaultZone
defaultLocale
defaultLocale
defaultNumberingSystem
defaultNumberingSystem
defaultOutputCalendar
defaultOutputCalendar
throwOnInvalid
throwOnInvalid
resetCaches()