JavaScript Date parse()
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 (JavaScript 1997) feature.
It is 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. |