JavaScript Date.prototype.getTime() Method
The getTime() method returns a date's timestamp: milliseconds since 1 January 1970 UTC. It's used to compare and subtract dates.
Description
The getTime() method returns the date as a timestamp in milliseconds since the epoch. Timestamps are easy to compare and subtract, so it's the basis of most date arithmetic. Comparing dates with === compares objects, not times, so compare their getTime() values instead.
It's equivalent to valueOf(), which is what makes arithmetic such as date2 - date1 work. For an invalid date it returns NaN, so isNaN(date.getTime()) is a reliable way to check that a date was parsed successfully.
Timestamps are the same everywhere in the world, regardless of time zone, which makes them the safest form for storing and comparing moments in time. Create a Date from one with new Date(timestamp).
Syntax
date.getTime()Return Value
The number of milliseconds since 1 January 1970 UTC, or NaN for an invalid date.
Example
Browser Support
The following information will show you the current browser support for the Date.prototype.getTime() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





