Date.prototype.getTime
Returns the date as a number of milliseconds.
Available since: ES1
Syntax
date.getTime()Return value
numberThe timestamp — milliseconds since January 1, 1970 UTC.
Examples
A timestamp:
console.log(new Date('2026-01-01T00:00:00Z').getTime());Output:
1767225600000The difference between dates in days:
const start = new Date('2026-03-01T00:00:00Z');
const end = new Date('2026-03-15T00:00:00Z');
const days = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
console.log(days);Output:
14Dates are compared by their timestamps:
const a = new Date('2026-03-15T00:00:00Z');
const b = new Date('2026-03-15T00:00:00Z');
console.log(a === b);
console.log(a.getTime() === b.getTime());Output:
false
trueNotes
Two dates are two objects, so === compares references, not moments. Compare getTime(). The < and > operators work on dates directly.
See also
- Date.now — Returns the current time as a number of milliseconds.
- Date — A date and time: creating, reading parts, calculating.
- Date.parse — Parses a date string and returns a timestamp.
Related recipes
In the tutorial
- Dates and time — The Date object in JavaScript: creating a date, reading the year, month and day, changing a date, the difference between dates and the ISO format.