Favorites

JavaScript Date.prototype.getTime() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Date.prototype.getTime()
JavaScript Date Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

const a = new Date('2026-01-01T00:00:00Z');
const b = new Date('2026-01-01T00:00:00Z');
console.log(a === b, a.getTime() === b.getTime());
const days = (new Date('2026-12-25') - new Date('2026-12-01')) / 86400000;
console.log(days);

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee