Easy Tutorial
❮ Prop Hidden Form Jsref Tolocalestring ❯

JavaScript parse() Method

JavaScript Date Object

Example

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

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

d Output result:

document.write(Date.parse("March 21, 2012"));

Definition and Usage

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


Browser Support

All major browsers support the parse() method.


Syntax

Parameter Values

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

#

Type Description
Number The number of milliseconds between January 1, 1970, midnight GMT and the specified date.

Technical Details

| JavaScript Version: | 1.0 | | --- | --- |


More Examples

Example

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

y Output result:

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

document.write(Math.floor(d / years));

JavaScript Date Object

❮ Prop Hidden Form Jsref Tolocalestring ❯