getters

Date.prototype.getTime

Returns the underlying timestamp of the date as milliseconds since the Unix epoch (1970-01-01T00:00:00Z). This is the canonical way to compare, subtract, or serialize a Date as a number.

date.getTime()

Parameters

Parameter Purpose
() no arguments; returns Number (integer ms)
valueOf() identical result; called implicitly by arithmetic operators

Examples

console.log(new Date('2026-07-19T00:00:00Z').getTime()); // 1784332800000

epoch ms

console.log(new Date('2026-07-20') - new Date('2026-07-19')); // 86400000

diff in ms via subtraction

const a = new Date(), b = new Date(a.getTime()); console.log(a.getTime() === b.getTime()); // true

clone by timestamp

Gotcha

Returns NaN for an Invalid Date (e.g. new Date('nope').getTime()). Prefer getTime() over Number(date) for readability.

Related

← All JS Date methods · Math methods · Cron syntax