Skip to content

Function: parseDate() ​

ts
function parseDate(v, calendar?): number | undefined;

Experimental

Convert a date value to milliseconds since the Unix epoch (UTC).

Accepts:

  • valid Date instances;
  • finite numbers, which are already milliseconds;
  • ISO-8601-style strings (every form isDateString matches). Date-only strings and strings without a UTC offset are read as UTC; Z and ±hh:mm/±hhmm offsets are honored; fractional seconds keep sub-millisecond precision. A month without a day means its first day.

Parameters ​

ParameterTypeDescription
vunknownThe value to convert.
calendar?string | CalendarSystemCalendar for the date part of strings. undefined and 'gregorian' use the proleptic Gregorian calendar. Other calendar names are reserved for world calendars (plan E3) and currently yield undefined; pass a CalendarSystem to supply one directly.

Returns ​

number | undefined

Milliseconds since the epoch, or undefined if v is not a date — including impossible dates such as 2023-02-29, which isDateString still matches.

Example ​

ts
parseDate('2024-03-01'); // 1709251200000
parseDate('2024-03-01 12:30+01:00'); // 1709292600000 (11:30 UTC)
parseDate(new Date(0)); // 0

Released under the MIT License.