Immutable date wrapper library for JavaScript with comprehensive date/time manipulation, timezone support, and internationalization capabilities.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The DateTime class is Luxon's primary date and time representation. It provides comprehensive functionality for creating, parsing, formatting, and manipulating dates and times with full timezone and locale support.
Methods for creating DateTime instances from various sources.
/**
* Current instant in the system's timezone
*/
static now(): DateTime;
/**
* Create a DateTime in the local timezone
* @param year - Calendar year
* @param month - Calendar month (1-12)
* @param day - Day of month
* @param hour - Hour (0-23)
* @param minute - Minute (0-59)
* @param second - Second (0-59)
* @param millisecond - Millisecond (0-999)
* @param opts - Options including zone, locale, numberingSystem
*/
static local(year?, month?, day?, hour?, minute?, second?, millisecond?, opts?): DateTime;
/**
* Create a DateTime in UTC
*/
static utc(year?, month?, day?, hour?, minute?, second?, millisecond?, opts?): DateTime;
/**
* Create from JavaScript Date object
* @param date - JavaScript Date
* @param opts - Options including zone and locale
*/
static fromJSDate(date: Date, opts?): DateTime;
/**
* Create from epoch milliseconds
* @param milliseconds - Milliseconds since Unix epoch
* @param opts - Options including zone and locale
*/
static fromMillis(milliseconds: number, opts?): DateTime;
/**
* Create from epoch seconds
* @param seconds - Seconds since Unix epoch
* @param opts - Options including zone and locale
*/
static fromSeconds(seconds: number, opts?): DateTime;
/**
* Create from object with date/time properties
* @param obj - Object with year, month, day, etc. properties
* @param opts - Options including zone and locale
*/
static fromObject(obj: object, opts?): DateTime;Methods for parsing DateTime from various string formats.
/**
* Parse from ISO 8601 string
* @param text - ISO 8601 formatted string
* @param opts - Parsing options including zone and setZone
*/
static fromISO(text: string, opts?): DateTime;
/**
* Parse from RFC 2822 string
* @param text - RFC 2822 formatted string
* @param opts - Parsing options
*/
static fromRFC2822(text: string, opts?): DateTime;
/**
* Parse from HTTP header date string
* @param text - HTTP date string
* @param opts - Parsing options
*/
static fromHTTP(text: string, opts?): DateTime;
/**
* Parse from custom format string
* @param text - Date string to parse
* @param fmt - Format pattern using Luxon tokens
* @param opts - Parsing options including locale
*/
static fromFormat(text: string, fmt: string, opts?): DateTime;
/**
* Parse from SQL date/time string
* @param text - SQL formatted string
* @param opts - Parsing options
*/
static fromSQL(text: string, opts?): DateTime;/**
* Create an invalid DateTime
* @param reason - Reason for invalidity
* @param explanation - Additional explanation
*/
static invalid(reason: string, explanation?: string): DateTime;
/**
* Check if object is a DateTime instance
* @param o - Object to check
*/
static isDateTime(o: any): boolean;
/**
* Return the minimum DateTime from arguments
* @param dateTimes - DateTime instances to compare
*/
static min(...dateTimes: DateTime[]): DateTime;
/**
* Return the maximum DateTime from arguments
* @param dateTimes - DateTime instances to compare
*/
static max(...dateTimes: DateTime[]): DateTime;
/**
* Explain how format parsing would work
* @param text - Text to parse
* @param fmt - Format pattern
* @param opts - Options
*/
static fromFormatExplain(text: string, fmt: string, opts?): object;
/**
* @deprecated Use fromFormat instead
* Parse from custom format string
* @param text - Text to parse
* @param fmt - Format pattern
* @param opts - Parsing options
*/
static fromString(text: string, fmt: string, opts?): DateTime;
/**
* @deprecated Use fromFormatExplain instead
* Explain how string parsing would work
* @param text - Text to parse
* @param fmt - Format pattern
* @param opts - Options
*/
static fromStringExplain(text: string, fmt: string, opts?): object;Access date/time components and metadata.
// Validation
isValid: boolean;
invalidReason: string | null;
invalidExplanation: string | null;
// Locale settings
locale: string;
numberingSystem: string;
outputCalendar: string;
// Timezone
zone: Zone;
zoneName: string;
offset: number;
offsetNameShort: string;
offsetNameLong: string;
isOffsetFixed: boolean;
isInDST: boolean;
// Calendar components
year: number;
quarter: number; // 1-4
month: number; // 1-12
day: number;
hour: number; // 0-23
minute: number; // 0-59
second: number; // 0-59
millisecond: number; // 0-999
// Week-based components
weekYear: number;
weekNumber: number;
weekday: number; // 1-7, Monday=1
ordinal: number; // Day of year
// Localized names
monthShort: string;
monthLong: string;
weekdayShort: string;
weekdayLong: string;
// Calendar calculations
isInLeapYear: boolean;
daysInMonth: number;
daysInYear: number;
weeksInWeekYear: number;/**
* Get value of specific unit
* @param unit - Unit name (year, month, day, etc.)
*/
get(unit: string): number;
/**
* Get resolved Intl options used for formatting
* @param opts - Format options to resolve
*/
resolvedLocaleOptions(opts?): object;
/**
* Convert to UTC
* @param offset - Specific offset or options
* @param opts - Additional options
*/
toUTC(offset?: number, opts?): DateTime;
/**
* Convert to local timezone
*/
toLocal(): DateTime;
/**
* Set timezone
* @param zone - Zone name or Zone instance
* @param opts - Options including keepLocalTime
*/
setZone(zone: string | Zone, opts?): DateTime;
/**
* Reconfigure locale settings
* @param opts - Locale, numberingSystem, outputCalendar
*/
reconfigure(opts: {locale?, numberingSystem?, outputCalendar?}): DateTime;
/**
* Set locale
* @param locale - Locale string
*/
setLocale(locale: string): DateTime;/**
* Set specific date/time values
* @param values - Object with date/time properties to set
*/
set(values: object): DateTime;
/**
* Add duration
* @param duration - Duration to add or object with duration units
*/
plus(duration: Duration | object): DateTime;
/**
* Subtract duration
* @param duration - Duration to subtract or object with duration units
*/
minus(duration: Duration | object): DateTime;
/**
* Go to start of time unit
* @param unit - Unit (year, month, week, day, hour, minute, second)
*/
startOf(unit: string): DateTime;
/**
* Go to end of time unit
* @param unit - Unit (year, month, week, day, hour, minute, second)
*/
endOf(unit: string): DateTime;/**
* Format with custom format string
* @param fmt - Format pattern using Luxon tokens
* @param opts - Options including locale
*/
toFormat(fmt: string, opts?): string;
/**
* Format using Intl.DateTimeFormat
* @param formatOpts - Intl.DateTimeFormat options
* @param opts - Additional options
*/
toLocaleString(formatOpts?, opts?): string;
/**
* Get Intl.DateTimeFormat parts
* @param opts - Intl.DateTimeFormat options
*/
toLocaleParts(opts?): object[];
/**
* ISO 8601 string
* @param opts - Options for suppressing fields and format
*/
toISO(opts?): string;
/**
* ISO 8601 date string (YYYY-MM-DD)
* @param opts - Options
*/
toISODate(opts?): string;
/**
* ISO 8601 week date string
*/
toISOWeekDate(): string;
/**
* ISO 8601 time string
* @param opts - Options for suppressing fields
*/
toISOTime(opts?): string;
/**
* RFC 2822 string
*/
toRFC2822(): string;
/**
* HTTP header date string
*/
toHTTP(): string;
/**
* SQL date string (YYYY-MM-DD)
*/
toSQLDate(): string;
/**
* SQL time string
* @param opts - Options including includeZone
*/
toSQLTime(opts?): string;
/**
* SQL datetime string
* @param opts - Options including includeZone
*/
toSQL(opts?): string;/**
* String representation (ISO format)
*/
toString(): string;
/**
* Epoch milliseconds (for sorting/comparison)
*/
valueOf(): number;
/**
* Epoch milliseconds
*/
toMillis(): number;
/**
* Epoch seconds
*/
toSeconds(): number;
/**
* Epoch seconds as integer
*/
toUnixInteger(): number;
/**
* JSON representation (ISO string)
*/
toJSON(): string;
/**
* BSON representation (JavaScript Date)
*/
toBSON(): Date;
/**
* JavaScript object with date/time properties
* @param opts - Options including includeConfig
*/
toObject(opts?): object;
/**
* JavaScript Date object
*/
toJSDate(): Date;/**
* Difference from other DateTime
* @param otherDateTime - DateTime to compare against
* @param unit - Unit or array of units for difference
* @param opts - Options including conversionAccuracy
*/
diff(otherDateTime: DateTime, unit?: string | string[], opts?): Duration;
/**
* Difference from current time
* @param unit - Unit or array of units for difference
* @param opts - Options including conversionAccuracy
*/
diffNow(unit?: string | string[], opts?): Duration;
/**
* Create interval until other DateTime
* @param otherDateTime - End DateTime
*/
until(otherDateTime: DateTime): Interval;
/**
* Check if same time unit as other DateTime
* @param otherDateTime - DateTime to compare
* @param unit - Unit to compare (year, month, day, etc.)
*/
hasSame(otherDateTime: DateTime, unit: string): boolean;
/**
* Check equality with other DateTime
* @param other - DateTime to compare
*/
equals(other: DateTime): boolean;/**
* Relative time string (e.g., "3 hours ago")
* @param opts - Options including base DateTime, style, unit, locale
*/
toRelative(opts?): string;
/**
* Relative calendar string (e.g., "tomorrow at 3:00 PM")
* @param opts - Options including base DateTime, locale
*/
toRelativeCalendar(opts?): string;Pre-defined format options for common date/time representations.
// Date formats
static DATE_SHORT: object; // 10/14/1983
static DATE_MED: object; // Oct 14, 1983
static DATE_MED_WITH_WEEKDAY: object; // Fri, Oct 14, 1983
static DATE_FULL: object; // October 14, 1983
static DATE_HUGE: object; // Tuesday, October 14, 1983
// Time formats
static TIME_SIMPLE: object; // 09:30 AM
static TIME_WITH_SECONDS: object; // 09:30:23 AM
static TIME_WITH_SHORT_OFFSET: object; // 09:30:23 AM EDT
static TIME_WITH_LONG_OFFSET: object; // 09:30:23 AM Eastern Daylight Time
static TIME_24_SIMPLE: object; // 09:30
static TIME_24_WITH_SECONDS: object; // 09:30:23
static TIME_24_WITH_SHORT_OFFSET: object; // 09:30:23 EDT
static TIME_24_WITH_LONG_OFFSET: object; // 09:30:23 Eastern Daylight Time
// DateTime formats
static DATETIME_SHORT: object; // 10/14/1983, 9:30 AM
static DATETIME_SHORT_WITH_SECONDS: object; // 10/14/1983, 9:30:33 AM
static DATETIME_MED: object; // Oct 14, 1983, 9:30 AM
static DATETIME_MED_WITH_SECONDS: object; // Oct 14, 1983, 9:30:33 AM
static DATETIME_MED_WITH_WEEKDAY: object; // Fri, 14 Oct 1983, 9:30 AM
static DATETIME_FULL: object; // October 14, 1983, 9:30 AM EDT
static DATETIME_FULL_WITH_SECONDS: object; // October 14, 1983, 9:30:33 AM EDT
static DATETIME_HUGE: object; // Friday, October 14, 1983, 9:30 AM Eastern Daylight Time
static DATETIME_HUGE_WITH_SECONDS: object; // Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Timeimport { DateTime } from "luxon";
// Creating DateTimes
const now = DateTime.now();
const specific = DateTime.local(2023, 12, 25, 10, 30);
const fromString = DateTime.fromISO("2023-12-25T10:30:00");
// Formatting
console.log(now.toFormat("yyyy-MM-dd HH:mm")); // "2023-10-25 14:30"
console.log(now.toLocaleString(DateTime.DATE_MED)); // "Oct 25, 2023"
// Manipulation
const tomorrow = now.plus({ days: 1 });
const startOfDay = now.startOf('day');
const endOfMonth = now.endOf('month');
// Timezone conversion
const utc = now.toUTC();
const ny = now.setZone('America/New_York');
// Comparisons
const diff = tomorrow.diff(now, 'hours');
console.log(diff.hours); // 24
const isAfter = tomorrow > now; // true
const isSameDay = now.hasSame(tomorrow.minus({ hours: 12 }), 'day');