JavaScript Date getTime()
Examples
Get the time:
const d = new Date();
let time = d.getTime();
Try it Yourself »
Calculate the number of years since January 1, 1970:
// Calculate milliseconds in a year
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;
// Divide Time with a year
const d = new Date();
let years = Math.round(d.getTime() / year);
Try it Yourself »
Description
getTime()
returns the number of milliseconds since January 1, 1970 00:00:00.
See Also:
Syntax
Date.getTime()
Parameters
NONE |
Return Value
Type | Description |
A number | Number of milliseconds since January 1, 1970 00:00:00. |
Browser Support
getTime()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |