Javascript - Date now() Method

The now() method returns the number of milliseconds since January 1, 1970 00:00:00 UTC.

Description

The now() method returns the number of milliseconds since January 1, 1970 00:00:00 UTC.

Syntax

Date.now()

Parameters

None

Return

A Number, representing the number of milliseconds since midnight January 1, 1970

Example

Return the number of milliseconds since 1970/01/01:

Demo

//The internal clock in JavaScript starts at midnight January 1, 1970.
//display the number of milliseconds since midnight, January 1, 1970.

var n = Date.now();
console.log(n);/*from  w  w w . ja va  2  s.  c om*/

//Calculate the number of years since 1970/01/01:

var minutes = 1000 * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;
var t = Date.now();

var y = Math.round(t / years);

console.log(y);

Result