parsing
Date.parse
Parses a date string and returns the corresponding milliseconds since the Unix epoch, or NaN if unrecognized. Only the ISO 8601 subset is guaranteed portable; any other format is implementation-defined.
Date.parse(dateString) Parameters
| Parameter | Purpose |
|---|---|
| 'YYYY-MM-DD' | date-only ISO string; treated as UTC |
| 'YYYY-MM-DDTHH:mm:ssZ' | full ISO instant with explicit UTC |
| 'YYYY-MM-DDTHH:mm:ss+HH:mm' | ISO with explicit offset |
Examples
console.log(Date.parse('2026-07-19T00:00:00Z')); // 1784332800000 ISO instant
console.log(Date.parse('2026-07-19')); // parsed as UTC midnight date-only is UTC
console.log(Date.parse('July 19, 2026')); // implementation-defined, avoid non-ISO is unreliable
console.log(Number.isNaN(Date.parse('not a date'))); // true invalid input yields NaN
Gotcha
Behavior for non-ISO strings varies by engine; always feed ISO 8601. 'YYYY-MM-DD' is interpreted as UTC but 'YYYY-MM-DDTHH:mm:ss' without a zone is LOCAL.
Related
Date.now
Returns the current time as an integer number of milliseconds since the Unix epoch without allocating a Date object. Use it for timestamps, expiry checks, and simple timing.
new Date()
Creates a Date object representing a single moment in time as milliseconds since the Unix epoch (1970-01-01T00:00:00Z). Called with no arguments it returns the current instant; with arguments it parses a timestamp, ISO string, or component parts.
Date.prototype.toISOString
Returns the date as an ISO 8601 extended-format string in UTC, always ending in 'Z'. This is the canonical machine-readable serialization and the format most APIs and databases accept.