JavaScript Date parse() Method
THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript Date parse() Method

❮ JavaScript Date Object

Example

Return the number of milliseconds between January 1, 1970 and March 21, 2012:

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

More "Try it Yourself" examples below.


Definition and Usage

The parse() method parses a date string and returns the number of milliseconds between the date string and midnight of January 1, 1970.


Browser Support

Method
parse() Yes Yes Yes Yes Yes

Syntax

Date.parse(datestring)

Parameter Values

Parameter Description
datestring Required. A string representing a date


Technical Details

Return Value: A Number, representing the number of milliseconds between the specified date-time and midnight January 1, 1970
JavaScript Version: ECMAScript 1

More Examples

Example

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

var d = Date.parse("March 21, 2012");
var minutes = 1000 * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;

var y = Math.round(d / years);
Try it Yourself »

❮ JavaScript Date Object