Latest web development tutorials

JavaScript parse () Method

Date Object Reference JavaScript Date Object

Examples

Returns the number of milliseconds between 1970/01/01 to 3/21/2012:

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

d output:


try it"

Definition and Usage

parse () method can parse a date and time string and returns 1970/1/1 midnight on that date from the time the number of milliseconds.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support parse () Method


grammar

Date .parse( datestring )

Parameter Value

参数 描述
datestring 必需。表示日期和时间的字符串。
Type 描述
Number 指定的日期和时间据 1970/1/1 午夜(GMT 时间)之间的毫秒数。

technical details

JavaScript version: 1.0


More examples

Examples

In this example, we will obtain the number of milliseconds from 1970/01/01 to 2012/03/21:

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);

y output:


try it"


Date Object Reference JavaScript Date Object