Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Date.prototype.getTime: epoch milliseconds

getTime returns a Date object’s time value as milliseconds since the Unix epoch, independent of time zone.

Version: ECMAScript 1 onward; example target: Node.js 24.22.2

Syntax

date.getTime()

date.getTime() returns the internal time value as a Number: milliseconds since 1970-01-01T00:00:00Z. Values before the epoch are negative. The result is independent of local time zone and equals date.valueOf(), making it useful for comparison, sorting, and cloning with new Date(date.getTime()).

For an invalid Date, the method returns NaN. Valid Date values are integral milliseconds limited by TimeClip to ±8.64e15. The method takes no arguments, does not mutate the object, and ignores extra arguments.

The receiver must have Date internal state; Date.prototype.getTime.call({}) throws TypeError. The method has existed since ECMAScript 1.

Examples

const original = new Date("2024-01-01T00:00:00.123Z");
const timestamp = original.getTime();
const clone = new Date(timestamp);

console.log(timestamp);
console.log(clone.getTime() === original.getTime(), clone === original);
console.log(new Date(-1).getTime());
console.log(Number.isNaN(new Date(NaN).getTime()));

Result

1704067200123
true false
-1
true

Sources