JavaScript Date parse()

Example 1

let ms = Date.parse("March 21, 2012");
Try it Yourself »

Description

parse() parses a date string and returns the time difference since January 1, 1970.

parse() returns the time difference in milliseconds.

Example 2

Calculate the number of years between January 1, 1970 to March 21, 2012:

// Calculate milliseconds in a year
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;

// Compute years
const d = Date.parse("March 21, 2012");
let years = Math.round(d / year);
Try it Yourself »

Browser Support

parse() is an ECMAScript1 (ES1) feature.

ES1 (JavaScript 1997) is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Syntax

Date.parse(datestring)

Parameters

datestring Required.
A string representing a date.

Return Value

A number.

Milliseconds since January 1, 1970 00:00:00 UTC.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.