JavaScript Date getTime() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

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()
CallWhat 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 ValueDescription
*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
Try It Yourself

How It Works

  1. Moon landing. The UTC string is before 1970, so getTime() is negative.
  2. Epoch. new Date(0) is exactly the epoch → 0.
  3. Meaning. The number is ms from 1970-01-01T00:00:00.000Z, not a clock field.
  4. No mutation. The Date values are unchanged.

Example 2 — Elapsed Milliseconds

Subtract two getTime() values to measure duration (MDN timing idea).

JavaScript
const start = new Date(2026, 0, 1, 12, 0, 0);
const end = new Date(2026, 0, 1, 12, 0, 5);

const elapsed = end.getTime() - start.getTime();
console.log(elapsed);        // 5000
console.log(elapsed / 1000); // 5 seconds
Try It Yourself

How It Works

  1. Two instants. end is five seconds after start.
  2. Subtract. Later minus earlier → elapsed milliseconds.
  3. Convert. Divide by 1000 for seconds (or 60000 for minutes).
  4. 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)
Try It Yourself

How It Works

  1. Source. birthday.getTime() reads the epoch ms.
  2. Write. copy.setTime(...) sets that same instant on another object.
  3. Equal. Both Dates now share the same getTime() value.
  4. Alt. new Date(birthday.getTime()) also builds a copy in one step.

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 Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · 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.

Next: Date.now()

Learn the static shortcut for reading the current epoch milliseconds without creating a Date object.

Date.now() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful