JavaScript Date.now()
Definition and Usage
Date.now()
returns the number of milliseconds since January 1, 1970.
Notes
Date.now() is a static method of the Date object.
You cannot use it on a date like myDate.now()
The syntax is always Date.now().
Example 2
Calculate the number of years since 1970/01/01:
// Calculate milliseconds in a year
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;
// Divide Date.now() with a year
let years = Math.round(Date.now() / year);
Try it Yourself »
Browser Support
Date.now()
is an ECMAScript5 (ES5) feature.
ES5 (JavaScript 2009) fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |
Syntax
Date.now()
Parameters
NONE |
Return Value
A number. The number of milliseconds since midnight January 1, 1970 00:00:00 UTC. |