JavaScript Date parse() method

Definition and usage

parse() This method parses a date string and returns the number of 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(), not through dateobject.parse() to call this method.

Example

Example 1

Returns the number of 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

Browserstøtte

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

Relaterede sider

Lær at:JavaScript dato

Lær at:JavaScript datoformat