Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript parse() method

JavaScript parse() method

Date Object Reference JavaScript Date object

Example

Returns the milliseconds between 1970/01/01 and 2012/3/21:

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

d Output result:

Try it »


Definition and Usage

The parse() method parses a date/time string and returns the number of milliseconds since midnight 1970/1/1 to the specified date/time.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the parse() method.


Syntax

Date

.parse(

datestring

)

Parameter value

Parameters Description
datestring Required. A string representing the date and time.

Type Description
Number The number of milliseconds between the specified date/time and midnight 1970/1/1 (GMT).

Technical Details

JavaScript version: 1.0


More examples

Example

In this example, we will get the 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.floor(d/years);

y Output result:


Try it »


Date Object Reference JavaScript Date object