Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Date.parse: date text to timestamp

Date.parse converts date text to epoch milliseconds or returns NaN when the text is unrecognized or outside the supported range.

Version: ECMAScript 1 onward; current date-time string rules; example target: Node.js 24.22.2

Syntax

Date.parse(dateString)

Date.parse(string) first converts its argument to text, then returns a time value in milliseconds since the epoch. The standard date-time format is an ISO 8601 form such as 2024-02-29T12:30:00+02:00. A date-only form such as 2024-02-29 is interpreted as UTC; a date-time without an offset is interpreted in the local time zone.

Invalid text or a value outside the TimeClip range ±8.64e15 produces NaN, not an exception. Converting the argument to text can still throw, for example for a Symbol. The format produced by toISOString() must be accepted; for dates with zero milliseconds, toString() and toUTCString() formats are also required. Support for other formats is implementation-dependent.

For data interchange, use the complete ISO form with Z or an explicit offset instead of ambiguous local notation. Date.parse has existed since the first ECMAScript edition; offset-free date rules were clarified in later editions.

Examples

const dateOnly = Date.parse("2024-02-29");
const withOffset = Date.parse("2024-02-29T12:30:00+02:00");

console.log(dateOnly, new Date(dateOnly).toISOString());
console.log(withOffset, new Date(withOffset).toISOString());
console.log(Number.isNaN(Date.parse("not a date")));

Result

1709164800000 2024-02-29T00:00:00.000Z
1709202600000 2024-02-29T10:30:00.000Z
true

Sources