Create an instance from an existing value with datetime(), read the current time with now(), or combine a calendar date with a time using at(). Instances are immutable, so every method that changes a value returns a new one.
create.js
import { date, datetime, now } from 'native-dates';const fromUtc = datetime('2026-11-16T17:30:00Z', 'America/Los_Angeles');const standup = date('2026-11-16').at('9:30am', 'America/Los_Angeles');const current = now();
Pass a time zone to view the instant in that zone, or omit it to use the default from configure():
A trailing Z or numeric offset in an input string identifies when the moment happened, while the instance uses the zone you pass or your configured default. Pass 'UTC' as the zone when you want UTC fields and date math.
Properties
Properties read the date and time in the instance’s time zone.
Property
Type
Description
text
string
Locale-formatted date, time, and short zone name, such as 'Nov 16, 2026, 9:30 AM PST'.
year, month, day
number
Calendar year, month (1–12), and day of month (1–31).
hour, minute, second
number
24-hour clock fields (0–23, 0–59, 0–59).
millisecond, microsecond, nanosecond
number
Sub-second clock fields (0–999).
zone
string
Canonical IANA zone ID or fixed offset, such as 'America/Los_Angeles' or 'UTC'.
offset
string
Active UTC offset at this instant, such as '-08:00'.
ISO day of the week, from 1 for Monday through 7 for Sunday.
weekStart
number
First day of this moment’s weeks from 1 to 7, following configure() or its locale.
quarter
number
Calendar quarter (1–4).
weekOfYear, dayOfYear
number
ISO week number (1–53) and day of the year (1–366).
daysInMonth, daysInYear, hoursInDay
number
Length of the current month, year, and local calendar day.
Time zone and fields
View the same moment in another zone or replace individual calendar and clock fields.
in()
dt.in(zone): DateTime
Returns a new DateTime representing the same instant in another time zone. Local calendar and clock properties update to match the target zone, while the underlying timestamp stays the same.
Parameters
zoneZonerequired
IANA time zone name such as 'Europe/Berlin', fixed UTC offset, or 'UTC'.
Returns
DateTime
A new DateTime at the same instant viewed in zone.
Returns a new DateTime with one or more calendar or clock fields replaced in the current time zone. Out-of-range dates such as February 30 throw a RangeError instead of rolling into the next month. Updating month or year without day clamps an overflowing day to the end of the target month.
Parameters
fieldsDateTimeFields | Unitrequired
Object of calendar or clock fields, or a single unit name when passing value.
valuenumber
Whole-number value for the given unit.
Returns
DateTime
A new DateTime in the same time zone with updated fields.
Adding days, weeks, months, or years keeps the same time of day across daylight saving changes. Adding hours, minutes, or seconds counts exact elapsed time.
Moves back to the start of a calendar or clock unit in this time zone. Week boundaries start on firstDay, the configured weekStart from configure(), or this moment’s active locale.
Parameters
unitUnitrequired
Calendar or clock unit from 'year' down to 'millisecond'.
firstDayDayOfWeek
First day of the week when rounding to a week, such as 'sunday' or 7.
Moves to the final millisecond of a calendar or clock unit in this time zone.
Parameters
unitUnitrequired
Calendar or clock unit from 'year' down to 'nanosecond'.
firstDayDayOfWeek
First day of the week when unit is 'week'.
Returns
DateTime
A new DateTime at the last millisecond of unit.
const nov = datetime('2026-11-18T14:45', 'UTC');nov.endOf('month').toString(); // '2026-11-30T23:59:59.999Z'
startOfNext()
dt.startOfNext(unit, firstDay?): DateTime
Moves forward to the start of the calendar or clock unit after the one containing this moment, in this time zone. The result is always a later moment, so from midnight the next day starts at the following midnight.
Pass a weekday name in place of a unit to get the start of the next day with that name. Calling next() finds the same day and keeps the time of day.
Parameters
unitUnit | Exclude<DayOfWeek, number>required
Calendar or clock unit from 'year' down to 'nanosecond', or a weekday name such as 'wednesday'.
firstDayDayOfWeek
First day of the week when unit is 'week'.
Returns
DateTime
A new DateTime at the start of the next unit, or of the next given weekday.
const standup = datetime('2026-11-16T09:30', 'America/New_York');standup.startOfNext('month').text; // 'Dec 1, 2026, 12:00 AM EST'standup.startOfNext('hour').text; // 'Nov 16, 2026, 10:00 AM EST'standup.startOfNext('wednesday').text; // 'Nov 18, 2026, 12:00 AM EST'standup.next('wednesday').text; // 'Nov 18, 2026, 9:30 AM EST'
startOfPrevious()
dt.startOfPrevious(unit, firstDay?): DateTime
Moves back to the start of the calendar or clock unit before the one containing this moment, in this time zone. A weekday name in place of a unit gives the start of the previous day with that name, whereas previous() keeps the time of day.
Parameters
unitUnit | Exclude<DayOfWeek, number>required
Calendar or clock unit from 'year' down to 'nanosecond', or a weekday name such as 'wednesday'.
firstDayDayOfWeek
First day of the week when unit is 'week'.
Returns
DateTime
A new DateTime at the start of the previous unit, or of the previous given weekday.
const standup = datetime('2026-11-16T09:30', 'America/New_York');standup.startOfPrevious('day').text; // 'Nov 15, 2026, 12:00 AM EST'standup.startOfPrevious('month').text; // 'Oct 1, 2026, 12:00 AM EDT'standup.startOfPrevious('wednesday').text; // 'Nov 11, 2026, 12:00 AM EST'
next()
dt.next(target): DateTime
Moves forward to the next given weekday or MonthDay at the same time of day. When already on that weekday or annual date, it advances to the following occurrence.
Parameters
targetDayOfWeek | MonthDayrequired
Weekday name such as 'friday', ISO number from 1 to 7, or recurring MonthDay.
Returns
DateTime
A new DateTime on the next matching date at the same local time.
Comparisons check when each moment happened, even if the two values use different time zones.
Comparing with ===
JavaScript’s === operator checks whether two variables point to the same object in memory. Call equals() to check whether two DateTime instances represent the same moment.
equals()
dt.equals(other): boolean
Returns true when both values represent the exact same instant, regardless of their time zones.
Parameters
otherDateTimeInputrequired
Another DateTime or any input accepted by datetime().
Returns
boolean
true if both values point to the same instant.
const ny = datetime('2026-11-16T12:00', 'America/New_York');const utc = datetime('2026-11-16T17:00Z', 'UTC');ny.equals(utc); // true
isBefore()
dt.isBefore(other): boolean
Returns true if this moment is earlier than the other.
Checks whether another moment falls in the same calendar or clock unit when both are viewed in this instance’s time zone. Calling isSame() without a unit checks exact instant equality.
Parameters
otherDateTimeInputrequired
Moment to compare against, viewed in this instance's time zone.
unitUnit
Calendar or clock unit to compare, such as 'day' or 'month'.
firstDayDayOfWeek
First day of the week when unit is 'week'.
Returns
boolean
true when both moments fall in the same unit in this time zone.
const la = datetime('2026-11-16T09:30', 'America/Los_Angeles');const lateUtc = datetime('2026-11-17T02:00Z', 'UTC');la.isSame(lateUtc, 'day'); // true (6:00 PM Nov 16 in Los Angeles)lateUtc.isSame(la, 'day'); // false (Nov 17 vs Nov 16 in UTC)
Calendar predicates
Zero-argument checks evaluated in the instance’s time zone:
Method
Type
Description
isPast(), isFuture()
boolean
Whether this instant is earlier or later than the current time.
isToday(), isTomorrow(), isYesterday()
boolean
Whether the local calendar date matches today, tomorrow, or yesterday in this zone.
isWeekday(), isWeekend()
boolean
Working day vs. weekend day in the active locale, such as Saturday and Sunday in en-US or Friday and Saturday in ar-SA.
isLeapYear()
boolean
Whether the local year is a leap year.
Measuring time
until()
dt.until(other): Durationdt.until(other, unit): number
Measures the time from this moment to another, returning a negative span when the target is earlier. Pass a unit name to get the total length as a single number instead of a Duration.
Parameters
otherDateTimeInputrequired
Target moment to measure toward.
unitUnit
Unit to return the total length in as a floating-point number.
Returns
Duration | number
A Duration counted in days and clock units, or a number when unit is given.
Creates a half-open DateTimeRange starting at this moment and ending before the target moment or elapsed duration. Throws a RangeError if the end is earlier than the start. Use for() to pass an explicit duration length (refusing endpoints and unitless numbers).
Parameters
endDateTimeInput | DurationInput | numberrequired
Target end moment, duration, or numeric count paired with unit.
unitUnit
Unit name when the first argument is a numeric count, such as 'hours' or 'days'.
Returns
DateTimeRange
A half-open DateTimeRange in this instance's time zone.
Formats the date and time in its active zone using built-in presets, custom names from configure(), Intl options objects, or token patterns.
Localized presets from 'LT' through 'llll' are built in alongside [brackets] for literal words. See Formatting for the full preset and token reference.
Parameters
specFormatSpecdefault 'medium'
Built-in or configured format name, Intl options object, or token pattern.
localestring
BCP 47 locale tag overriding this moment's or the configured locale for one call.
Formats the elapsed distance from another moment to this one as a localized phrase via Intl.RelativeTimeFormat, such as '3 hours ago' or 'in 2 days'.
Omitting the first argument compares against the current moment, and formatRelative() works as an alias. Zero seconds prints 'now', while days, months, and years use numeric counts rather than calendar words like yesterday.
Parameters
otherDateTimeInput
Reference moment to measure from, interpreted in this instance's time zone when unzoned. Defaults to the current moment.
localeLocale
BCP 47 locale tag overriding this moment's or the configured locale for one call.
Reads the locale carried on this moment, or returns a copy that formats and starts weeks in another locale across presets, week boundaries, and derived values. Underscore tags and Accept-Language headers normalize automatically, an empty tag clears it, and lang() is an alias.
Parameters
tagLocale | null | undefined
Locale tag, tag array, or Accept-Language header to carry forward, or null to clear it.
Returns
DateTime | Locale | undefined
The active tag when called with no arguments, or a new DateTime carrying tag.
const standup = datetime('2026-11-16T09:30', 'Europe/Berlin').locale('es-ES');standup.locale(); // 'es-ES'standup.plus(1, 'week').date.format('long'); // '23 de noviembre de 2026'standup.locale(null).locale(); // undefined
Converts this moment to another kind inside a method chain without stopping for property access, including YearMonth and MonthDay values in its active time zone.
Returns the instant as a UTC ISO 8601 string, suitable for databases, URLs, and network payloads. toJSON() returns the same string for JSON.stringify().
Returns
string
UTC ISO 8601 timestamp, such as '2026-11-16T17:30:00.000Z'.