Date.prototype.getTime() returns the number of milliseconds since the Unix epoch (midnight, January 1, 1970, UTC) for this date (MDN). It is read-only and does not change the Date.
Remember
date.getTime()
→ milliseconds since 1970-01-01T00:00:00.000Z
→ NaN if the Date is invalid
Example (MDN):
new Date("July 20, 69 20:17:40 GMT+00:00").getTime()
→ -14182940000
getTime() ≡ valueOf() (same number)
Date.now() → current epoch ms (no Date object)
Syntax
Call date.getTime. Start with this line.
JavaScript
date.getTime()
Call
What it does
date.getTime()
Primary signature.
date.getTime(...)
Call with the arguments your case needs.
Built into JavaScript. Call getTime(...) on a Date instance — no import required.
Library declarations
JavaScript
date.getTime()
Parameters
This method has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Epoch milliseconds (number)
JavaScript Examples
Example 1 — Read Epoch Milliseconds
Call getTime() on fixed instants (MDN moon-landing style).
JavaScript
const moonLanding = new Date("July 20, 69 20:17:40 GMT+00:00");
const epoch = new Date(0);
console.log(moonLanding.getTime()); // -14182940000
console.log(epoch.getTime()); // 0
Subtract. Later minus earlier → elapsed milliseconds.
Convert. Divide by 1000 for seconds (or 60000 for minutes).
Tip. For “now” timers, MDN also suggests Date.now() to avoid extra Date objects.
Example 3 — Copy a Date with setTime()
Assign the same instant to another Date (MDN copy pattern).
JavaScript
// Month is zero-based: 12 → January of the next year
const birthday = new Date(1994, 12, 10);
const copy = new Date();
copy.setTime(birthday.getTime());
console.log(copy.getTime() === birthday.getTime()); // true
console.log(copy.getFullYear()); // 1995
console.log(copy.getMonth()); // 0 (January)
Write.copy.setTime(...) sets that same instant on another object.
Equal. Both Dates now share the same getTime() value.
Alt.new Date(birthday.getTime()) also builds a copy in one step.
Compatibility
Browser & Runtime Support
Date.prototype.getTime() is part of the language from early ECMAScript and is Baseline Widely available (MDN).
✓ Baseline · Widely available
Date.prototype.getTime()
Supported in every modern browser and Node.js. No polyfill needed for ordinary web apps.
99%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Date.getTime()Excellent
Bottom line: Safe everywhere. Focus on invalid-Date checks and choosing getTime vs Date.now vs performance.now rather than feature detection.
Frequently Asked Questions
A number: milliseconds since January 1, 1970 00:00:00 UTC (the Unix epoch) for that Date instant. Invalid Dates return NaN.
getTime() is called on a Date instance. Date.now() is a static method that returns the current epoch milliseconds without creating a Date. For “now”, new Date().getTime() matches Date.now().
getTime() returns the full epoch timestamp (e.g. 1721203200000). getMilliseconds() returns only 0–999 for the fraction inside the current second.
NaN. Detect invalid dates with Number.isNaN(date.getTime()).
No. The same instant returns the same getTime() everywhere. Local getters like getHours() can differ; getTime() identifies the UTC-based instant.
Yes for Date instances — MDN notes they are functionally equivalent. Date subtraction uses valueOf(), which is the same millisecond number.