Core parses strict ISO 8601 strings by default, while @native-dates/plugins/loose reads free-form text in the active locale. Importing this plugin adds a { format } option for fixed-layout strings such as bank exports and server logs.
Strict ISO parsing stays the default wherever you omit the format option. Calling any factory with { format } before importing this plugin throws a missingPlugin error.
Strict matching and named formats
Patterns use the core token vocabulary. Fixed-width tokens require exact digit counts, and literal text must match the full string case-sensitively.
Impossible dates like February 30 and mismatched weekdays throw instead of rolling forward. Repeated tokens or conflicting 12-hour and 24-hour clock fields are rejected the same way.
Named patterns registered in configure() work for both parsing and formatting. Range factories forward the format option to both endpoints, including duration lengths as the second argument.
Localized names and ordinals
Month names, weekday names, day periods, and ordinals follow the active locale. Both standalone and inflected month forms match case-insensitively, so Russian and Greek dates parse without extra rules.
The active locale follows the same order as formatting: the per-call option, then configure(), then the runtime default. Pass a locale explicitly whenever input text comes from a fixed language such as English server logs.
English ordinal tokens validate the exact suffix, so '24st' is rejected, while custom weekday names registered in app settings apply automatically.
ISO week and ordinal dates
Ordinal day-of-year and ISO week patterns resolve straight to calendar dates or moments. Beside a week token, YYYY reads the ISO week-year rather than the calendar year written by format(), so '2026-W01-1' resolves to December 29, 2025.
Leap years and 52- or 53-week years are checked strictly, and omitting a weekday on an ISO week lands on Monday.
Patterns with an offset token fix an exact instant and convert it into your target zone. Inline z tokens resolve IANA identifiers and, with @native-dates/plugins/zones, city names or abbreviations like JST, rather than arbitrary offset labels like GMT+2.
An inline zone stays on the result unless you pass a target zone option to convert into. If a string carries both an offset and a zone name that disagree for that instant, parsing throws.
Unix timestamps parse through X for whole seconds and x for milliseconds. Passing a date-only pattern to a datetime factory starts at the beginning of that day in the target zone.
Combining with loose mode
Load @native-dates/plugins/loose alongside this plugin to return null instead of throwing when input text does not match the format. Missing values, numbers, impossible dates, and rejected DST transitions return null from factory functions, while existing date and time instances pass through unchanged.
Loose mode only turns mismatched input strings into null. An empty or incomplete pattern throws unknownFormat, and a token the target type does not carry throws unsupportedToken.
Supported tokens
Tokens follow the formatting vocabulary, with leading and trailing whitespace trimmed automatically unless the pattern itself starts or ends with whitespace.
Token
Example
Matches
YYYY
'2026'
Four-digit calendar year, or ISO week-year when paired with W or WW.
YY
'26'
Two-digit year, reading 69 through 99 as 1969–1999 and 00 through 68 as 2000–2068.
M, MM
'9', '09'
Month number from 1 through 12, unpadded or zero-padded to two digits.
MMM, MMMM
'Nov', 'November'
Localized short or full Gregorian month name, including inflected forms.
D, DD
'6', '06'
Day of the month from 1 through 31, unpadded or zero-padded to two digits.
Do
'24th', '6.'
Day of the month with English ordinals or the active locale’s day marker.
DDD, DDDD
'1', '328'
ISO ordinal day of the year from 1 through 366, unpadded or zero-padded to three digits.
W, WW
'5', '48'
ISO week of the year from 1 through 53, unpadded or zero-padded to two digits.
E
'2'
ISO day of the week from 1 for Monday through 7 for Sunday.
d
'0'
Day of the week from 0 for Sunday through 6 for Saturday.
dd, ddd, dddd
'Tu', 'Tue', 'Tuesday'
Localized shortest, abbreviated, or full weekday name.
H, HH
'9', '09'
24-hour clock hour from 0 through 23, unpadded or zero-padded to two digits.
h, hh
'9', '09'
12-hour clock hour from 1 through 12, unpadded or zero-padded to two digits.
m, mm
'5', '05'
Minute from 0 through 59, unpadded or zero-padded to two digits.
s, ss
'8', '08'
Second from 0 through 59, unpadded or zero-padded to two digits.
S, SS, SSS
'5', '25', '250'
Fractional seconds in tenths, hundredths, or milliseconds.
A, a
'PM', 'pm'
Case-insensitive AM or PM in English, or the active locale’s day period.
Z, ZZ
'-05:00', '-0500'
UTC offset with or without a colon, or Z for UTC.
z, zz
'UTC', 'JST'
Non-whitespace IANA zone ID, or a city or abbreviation when @native-dates/plugins/zones is loaded. Does not parse offset labels like 'GMT+2'.
X, x
'1795542001'
Unix timestamp in whole seconds or milliseconds, including negative values.
[text]
'[W]'
Escaped literal text matched case-sensitively. Bare T also passes through unescaped.
Formatting-only tokens such as quarters and long zone names cannot be parsed and throw unknownFormat. Patterns missing required fields for the target type throw the same error, while tokens the target type does not carry throw unsupportedToken.
Factory options
datetime()
datetime(input, { format, zone?, locale?, disambiguation?, loose? }): DateTimedate(input, { format, locale?, loose? }): CalendarDatetime(input, { format, locale?, loose? }): TimeyearMonth(input, { format, locale?, loose? }): YearMonthmonthYear(input, { format, locale?, loose? }): YearMonthmonthDay(input, { format, locale?, loose? }): MonthDaydayMonth(input, { format, locale?, loose? }): MonthDaydateRange(start, end, { format, locale?, loose? }): DateRangedatetimeRange(start, end, { format, zone?, locale?, disambiguation?, loose? }): DateTimeRangetimeRange(start, end, { format, locale?, loose? }): TimeRange
Parses string input against a token pattern or named format across every date, time, partial-date, and range factory. Already-parsed date, time, Date, and Temporal values pass through after the pattern is validated, while numbers are rejected.
Parameters
formatstringrequired
Token pattern such as 'DDMMYYYY' or a named pattern registered in configure({ formats }).
zoneZone
Time zone used to interpret local date-time strings or convert offset and epoch timestamps.
localeLocale
BCP 47 locale tag carried on the value and used for month names, weekday names, day periods, and ordinals.
disambiguationDisambiguationdefault 'compatible'
How to resolve DST gaps and folds on local date-time strings. 'reject' throws invalidDateTime, or returns null with loose mode.
loosebooleandefault false
Requires @native-dates/plugins/loose. Return null when input does not match the format instead of throwing.
Returns
DateTime | CalendarDate | Time | YearMonth | MonthDay | Range
Parsed instance, or null when { loose: true } is set on a factory and the input does not match.