JavaScript Date parse() Method

Definition and Usage

parse() This method parses a date string and returns the milliseconds between the date string and midnight on January 1, 1970.

Description

This is a static method of the Date object. It is generally called in the form of Date.parse(), rather than through dateobject.parse() to call this method.

Example

Example 1

Returns the milliseconds between January 1, 1970, and March 21, 2012:

var d = Date.parse("March 21, 2012");

Try It Yourself

Example 2

Calculate the number of years between January 1, 1970, and 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

Syntax

Date.parse(datestring)

Parameter

Parameter Description
datestring Required. A string representing the date.

Technical Details

Return value: A number representing the milliseconds between the specified date and time and midnight on January 1, 1970 (GMT time).
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
parse() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format