Date

Date.parse

Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC

Syntax

JavaScript
Date.parse(dateString)

Parameters

ParameterTypeDescription
dateStringstringA string conforming to the date time format

Return Value

Milliseconds since epoch, or NaN if the string is not a valid date

Examples

Basic Usage
console.log(Date.parse('2024-01-15')); // 1705276800000
console.log(Date.parse('invalid')); // NaN
Practical Example
const ms = Date.parse('2024-06-15T12:00:00Z');
const date = new Date(ms);
console.log(date.toISOString());
Advanced Usage
const dates = ['2024-01-01', '2024-06-15', '2024-12-31'];
const sorted = dates.sort((a, b) => Date.parse(a) - Date.parse(b));
console.log(sorted);

Understanding Date.parse

The Date.parse method in JavaScript parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. It belongs to the Date object and is one of the most widely used methods for working with date values in modern JavaScript and TypeScript applications.

The method signature is Date.parse(dateString). It accepts 1 parameter: dateString. When called, it returns milliseconds since epoch, or nan if the string is not a valid date. Understanding when and how to use parse() helps you write more expressive, readable code.

Common use cases for Date.parse include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-now, date-gettime, date-toisostring, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Date.parse is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Date Methods

Other methods in the Date object

Related Tools

More Date Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.