Date.prototype.getTime()

Returns the timestamp of a Date as milliseconds since the epoch.

Since ES1 Spec ↗

Syntax

date.getTime()

Returns

number — Milliseconds since 1 January 1970 UTC, or `NaN` for an invalid date.

Examples

const d = new Date("2020-01-01T00:00:00Z");
console.log(d.getTime());
Output
1577836800000
const a = new Date(0);
console.log(a.getTime());
Output
0

Notes

- Equivalent to `date.valueOf()` and the numeric coercion of a date. - Subtract two `getTime()` results to get a duration in milliseconds.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also