Javascript - Date parse() Method

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

Description

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

Syntax

Date.parse(datestring)

Parameter Values

ParameterRequire Description
datestring Required. A string representing a date

Return

A Number, representing the number of milliseconds between the specified date-time and midnight January 1, 1970

Example

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

Demo

//display milliseconds between a specified date and January 1, 1970.
var d = Date.parse("March 21, 2012");
console.log(d);/*  www.  j  ava 2 s .  co m*/

//Calculate the number of years between 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.round(d / years);

console.log(y);

Result