Skip to main content
Version: 3.28.0

Date.prototype.getTime()

The getTime() method returns the number of milliseconds since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.

You can use this method to help assign a date and time to another Date object. This method is functionally equivalent to the Date.prototype.valueOf() method.

Syntax

getTime()

Return value

A number representing the milliseconds elapsed between 1 January 1970 00:00:00 UTC and the given date.

Description

To offer protection against timing attacks and fingerprinting, the precision of new Date().getTime() might get rounded depending on browser settings.

// reduced time precision (2ms) in Firefox 60
new Date().getTime();
// 1519211809934
// 1519211810362
// 1519211811670
// …

// reduced time precision with `privacy.resistFingerprinting` enabled
new Date().getTime();
// 1519129853500
// 1519129858900
// 1519129864400
// …