DateTime
The DateTime immutable class represents a datetime broken down into year, month, day, hour, minute, second, millisecond, and offset. It provides a variety of methods for creation, formatting, comparison, calculation, and conversion of datetime instances.
TIP
All instances of DateTime are immutable!
So all manipulation methods return a new instance of datetime.
Table of Contents
Instance Properties
year
Return the year of the datetime.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.year); // 2024month
Return the month of the datetime.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.month); // 12day
Return the day of the datetime.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.day); // 7hour
Return the hour of the datetime.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.hour); // 13minute
Return the minute of the datetime.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.minute); // 56second
Return the second of the datetime.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.second); // 19millisecond
Return the millisecond of the datetime.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.millisecond); // 920offset
Return the offset of the datetime.
- Type:
Offset
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.offset.toString()); // UTC+01:00daysSinceEpoch
Returns the total datetime in days since epoch.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.daysSinceEpoch); // 20064.539119444446hoursSinceEpoch
Returns the total datetime in hours since epoch.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.hoursSinceEpoch); // 481548.9388666667minutesSinceEpoch
Returns the total datetime in minutes since epoch.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.minutesSinceEpoch); // 28892936.332secondsSinceEpoch
Returns the total datetime in seconds since epoch.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.secondsSinceEpoch); // 1733576179.92millisecondsSinceEpoch
Returns the total datetime in milliseconds since epoch.
- Type:
number
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.millisecondsSinceEpoch); // 1733576179920durationSinceEpoch
Returns the total datetime in duration since epoch.
- Type:
Duration
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.durationSinceEpoch.toString()); // 20064 days 12:56:19.920Instance Methods
valueOf
Returns the total datetime in milliseconds.
valueOf(): number- Parameters:
void - Returns:
number - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.valueOf()); // 1733576179920toString
Returns the human-readable string representation of the datetime.
toString(): string- Parameters:
void - Returns:
string - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.toString()); // 2024-12-07 13:56:19.920 UTC+01:00[Symbol.toPrimitive]
Custom implementation to handle coercion.
[Symbol.toPrimitive](hint: string): number | string- Parameters:
hint:- description: The hint type (
"number"or"string") - Type:
string
- description: The hint type (
- Returns:
string | number - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(+datetime); // 1733576179920
console.log(`${datetime}`); // 2024-12-07 13:56:19.920 UTC+01:00toJSON
Returns the JSON serialization representation of the datetime.
toJSON(): string- Parameters:
void - Returns:
string - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.toJSON()); // "2024-12-07T13:56:19.920+01:00"toISOString
Returns the ISO 8601 representation of the datetime.
toISOString(): string- Parameters:
void - Returns:
string - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.toISOString()); // 2024-12-07T13:56:19.920+01:00toLocaleString
Returns the locale representation of the datetime.
toLocaleString(localeName: string): string- Parameters:
localeName:- description: The locale to represent the datetime in.
- Type:
string
- Returns:
string - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.toLocaleString("en-GB")); // 07/12/2024, 13:56:19toObject
Returns the object literal of the datetime.
toObject(): Object- Parameters:
void - Returns:
Object - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.toObject()); // { year: 2024, month: 12, day: 7, hour: 13, minute: 56, second: 19, millisecond: 920, offset: { hour: 1 }}toJSDate
Returns the js date of the datetime.
toJSDate(): Date- Parameters:
void - Returns:
Date - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime.toJSDate().toISOString()); // 2024-12-07T12:56:19.920Zequals
Returns whether the datetime is equal to the other datetime.
equals(other: DateTime): boolean- Parameters:
other:- description: The other datetime to compare against.
- Type:
DateTime
- Returns:
boolean - Throws:
void
Example:
const datetime1 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetime2 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime1.equals(datetime2)); // trueisLaterThan
Returns whether the datetime is later than the other datetime.
isLaterThan(other: DateTime): boolean- Parameters:
other:- description: The other datetime to compare against.
- Type:
DateTime
- Returns:
boolean - Throws:
void
Example:
const datetime1 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetime2 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime1.isLaterThan(datetime2)); // falseisEarlierThan
Returns whether the datetime is earlier than the other datetime.
isEarlierThan(other: DateTime): boolean- Parameters:
other:- description: The other datetime to compare against.
- Type:
DateTime
- Returns:
boolean - Throws:
void
Example:
const datetime1 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetime2 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(datetime1.isEarlierThan(datetime2)); // falsewithYear
Return a new datetime with year replaced.
withYear(year: number): DateTime- Parameters:
year:- description: The year to replace the old one.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithYear = datetime.withYear(2023);
console.log(datetimeWithYear.toString()); // 2023-12-07 13:56:19.920 UTC+01:00withMonth
Return a new datetime with month replaced.
withMonth(month: number): DateTime- Parameters:
month:- description: The month to replace the old one.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithMonth = datetime.withMonth(9);
console.log(datetimeWithMonth.toString()); // 2024-09-07 13:56:19.920 UTC+01:00withDay
Return a new datetime with day replaced.
withDay(day: number): DateTime- Parameters:
day:- description: The day to replace the old one.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithDay = datetime.withDay(28);
console.log(datetimeWithDay.toString()); // 2024-12-28 13:56:19.920 UTC+01:00withHour
Return a new datetime with hour replaced.
withHour(hour: number): DateTime- Parameters:
hour:- description: The hour to replace the old one.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithHour = datetime.withHour(21);
console.log(datetimeWithHour.toString()); // 2024-12-07 21:56:19.920 UTC+01:00withMinute
Return a new datetime with minute replaced.
withMinute(minute: number): DateTime- Parameters:
minute:- description: The minute to replace the old one.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithMinute = datetime.withMinute(59);
console.log(datetimeWithMinute.toString()); // 2024-12-07 13:59:19.920 UTC+01:00withSecond
Return a new datetime with second replaced.
withSecond(second: number): DateTime- Parameters:
second:- description: The second to replace the old one.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithSecond = datetime.withSecond(59);
console.log(datetimeWithSecond.toString()); // 2024-12-07 13:56:59.920 UTC+01:00withMillisecond
Return a new datetime with millisecond replaced.
withMillisecond(millisecond: number): DateTime- Parameters:
millisecond:- description: The millisecond to replace the old one.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithMillisecond = datetime.withMillisecond(999);
console.log(datetimeWithMillisecond.toString()); // 2024-12-07 13:56:19.999 UTC+01:00withOffset
Return a new datetime with offset replaced.
WARNING
This method returns a datetime with other fields un-changed.
If you want to reflect the same datetime in another offset use inOffset.
withOffset(offset: Offset): DateTime- Parameters:
offset:- description: The offset to replace the old one.
- Type:
Offset
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeWithOffset = datetime.withOffset(Offset.fromObject({ hour: -1 }));
console.log(datetimeWithOffset.toString()); // 2024-12-07 13:56:19.920 UTC-01:00inOffset
Return the same datetime reflected in another offset.
WARNING
This method returns a datetime with other fields changed.
If you want to replace just the offset and not anything else use withOffset.
inOffset(offset: Offset): DateTime- Parameters:
offset:- description: The offset to return the datetime in.
- Type:
Offset
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeInOffset = datetime.inOffset(Offset.UTC);
console.log(datetimeInOffset.toString()); // 2024-12-07 12:56:19.920 UTCinZone
Return the same datetime reflected in another timezone.
WARNING
This method returns a datetime with other fields changed.
inZone(zoneName: string): DateTime- Parameters:
zoneName:- description: The zone name to return the datetime in.
- Type:
string
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeInZone = datetime.inZone("UTC");
console.log(datetimeInZone.toString()); // 2024-12-07 12:56:19.920 UTCinUTC
Return the same datetime reflected in UTC.
WARNING
This method returns a datetime with other fields changed.
inUTC(): DateTime- Parameters:
void - Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetimeInUTC = datetime.inUTC();
console.log(datetimeInUTC.toString()); // 2024-12-07 12:56:19.920 UTCplus
Return a new datetime as the sum of the datetime with a duration.
plus(duration: Duration): DateTime- Parameters:
duration:- description: The duration to add.
- Type:
Duration
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const duration = Duration.fromObject({ millisecond: 10 });
const sum = datetime.plus(duration);
console.log(sum.toString()); // 2024-12-07 13:56:19.930 UTC+01:00minus
Return a new datetime as the difference of the datetime with a duration.
minus(duration: Duration): DateTime- Parameters:
duration:- description: The duration to subtract.
- Type:
Duration
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const duration = Duration.fromObject({ millisecond: 10 });
const diff = datetime.minus(duration);
console.log(diff.toString()); // 2024-12-07 13:56:19.910 UTC+01:00Static Properties
None
Static Methods
fromDaysSinceEpoch
Return a new datetime from days since epoch.
INFO
This method returns the datetime reflected in your local timezone.
DateTime.fromDaysSinceEpoch(daysSinceEpoch: number): DateTime- Parameters:
daysSinceEpoch:- description: the days since epoch.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromDaysSinceEpoch(20064.539119444446);
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casefromHoursSinceEpoch
Return a new datetime from hours since epoch.
INFO
This method returns the datetime reflected in your local timezone.
DateTime.fromHoursSinceEpoch(hoursSinceEpoch: number): DateTime- Parameters:
hoursSinceEpoch:- description: the hours since epoch.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromHoursSinceEpoch(481548.9388666667);
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casefromMinutesSinceEpoch
Return a new datetime from minutes since epochs.
INFO
This method returns the datetime reflected in your local timezone.
DateTime.fromMinutesSinceEpoch(minutesSinceEpoch: number): DateTime- Parameters:
minutesSinceEpoch:- description: the minutes since epoch.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromMinutesSinceEpoch(28892936.332);
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casefromSecondsSinceEpoch
Return a new datetime from seconds since epoch.
INFO
This method returns the datetime reflected in your local timezone.
DateTime.fromSecondsSinceEpoch(secondsSinceEpoch: number): DateTime- Parameters:
secondsSinceEpoch:- description: the seconds since epoch.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromSecondsSinceEpoch(1733576179.92);
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casefromMillisecondsSinceEpoch
Return a new datetime from milliseconds since epoch.
INFO
This method returns the datetime reflected in your local timezone.
DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch: number): DateTime- Parameters:
millisecondsSinceEpoch:- description: the milliseconds since epoch.
- Type:
number
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromMillisecondsSinceEpoch(1733576179920);
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casefromDurationSinceEpoch
Return a new datetime from duration since epoch.
INFO
This method returns the datetime reflected in your local timezone.
DateTime.fromDurationSinceEpoch(durationSinceEpoch: Duration): DateTime- Parameters:
durationSinceEpoch:- description: the duration since epoch.
- Type:
Duration
- Returns:
DateTime - Throws:
void
Example:
const durationSinceEpoch = Duration.fromObject({
day: 20064,
hour: 12,
minute: 56,
second: 19,
millisecond: 920,
});
const datetime = DateTime.fromDurationSinceEpoch(durationSinceEpoch);
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casefromObject
Return a new datetime from an object literal.
DateTime.fromObject(object: Object): DateTime- Parameters:
object:- description: the object literal.
- Type:
Object
- Returns:
DateTime - Throws:
void
Example:
const objectLiteral = {
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
};
const datetime = DateTime.fromObject(objectLiteral);
console.log(datetime.toString()); // 2024-12-07 13:56:19.920 UTC+01:00fromString
Return a new datetime from a human-readable string representation.
DateTime.fromString(str: string): DateTime- Parameters:
str:- description: the human-readable string representation.
- Type:
string
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromString("2024-12-07 13:56:19.920 UTC+01:00");
console.log(datetime.toObject()); // {year: 2024, month: 12, day: 7, hour: 13, minute: 56, second: 19, millisecond: 920, offset: { hour: 1 }}fromISOString
Return a new datetime from an ISO 8601 representation.
DateTime.fromISOString(str: string): DateTime- Parameters:
str:- description: the ISO 8601 representation.
- Type:
string
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.fromISOString("2024-12-07T13:56:19.920+01:00");
console.log(datetime.toObject()); // {year: 2024, month: 12, day: 7, hour: 13, minute: 56, second: 19, millisecond: 920, offset: { hour: 1 }}parse
Return a new datetime from any possible string.
DateTime.parse(str: string): DateTime- Parameters:
str:- description: the string.
- Type:
string
- Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.parse("2024-12-07 13:56:19.920 UTC+01:00");
console.log(datetime.toObject()); // {year: 2024, month: 12, day: 7, hour: 13, minute: 56, second: 19, millisecond: 920, offset: { hour: 1 }}fromJSDate
Return a new datetime from a js date.
INFO
This method returns the datetime reflected in your local timezone.
DateTime.fromJSDate(date: Date): DateTime- Parameters:
date:- description: the js date.
- Type:
Date
- Returns:
DateTime - Throws:
void
Example:
const jsDate = new Date(Date.UTC(2024, 11, 7, 12, 56, 19, 920));
const datetime = DateTime.fromJSDate(jsDate);
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casenow
Return the current datetime reflected in your local timezone.
DateTime.now(): DateTime- Parameters:
void - Returns:
DateTime - Throws:
void
Example:
const datetime = DateTime.now();
console.log(datetime.toString()); // 2024-12-07 12:56:19.920 UTC - local timezone is assumed to be UTC in this casecompare
Returns the difference between two datetime instances.
TIP
This method is useful for sorting DateTime instances in an array.
DateTime.compare(datetime1: DateTime, datetime2: DateTime): number- Parameters:
datetime1:- description: The first datetime.
- Type:
DateTime
datetime2:- description: The second datetime.
- Type:
DateTime
- Returns:
number - Throws:
void
Example:
const datetime1 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
const datetime2 = DateTime.fromObject({
year: 2024,
month: 12,
day: 7,
hour: 13,
minute: 56,
second: 19,
millisecond: 920,
offset: { hour: 1 },
});
console.log(DateTime.compare(datetime1, datetime2)); // 0