JavaScript Date valueOf() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.valueOf() returns the milliseconds since January 1, 1970 UTC (the Unix epoch) for that Date. It is functionally the same as getTime().

Remember
date.valueOf()

→ number (ms since 1970-01-01 UTC)
→ same as date.getTime()
→ NaN if the Date is invalid

new Date(0).valueOf()     → 0
+date                     → same idea (coercion)
dateB - dateA             → elapsed ms

Syntax

Call date.valueOf. Start with this line.

JavaScript
date.valueOf()
CallWhat it does
date.valueOf()Primary signature.
date.valueOf(...)Call with the arguments your case needs.

Built into JavaScript. Call valueOf(...) on a Date instance — no import required.

Library declarations
JavaScript
date.valueOf()

Parameters

ParameterDescription
dateRequired. Date instance to read

Return Value

Return ValueDescription
*Epoch ms (number), or NaN if invalid

JavaScript Examples

Example 1 — Read the Epoch Milliseconds

Call valueOf() on a UTC-built Date (MDN-style example).

JavaScript
const date1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5));

console.log(date1.valueOf());
// 823230245000

const date2 = new Date("02 Feb 1996 03:04:05 GMT");

console.log(date2.valueOf());
// 823230245000
Try It Yourself

How It Works

  1. Build the same instant two ways. Date.UTC parts and a GMT string both mean Feb 2, 1996 03:04:05 UTC.
  2. Call valueOf(). Each Date returns its internal timestamp as a number.
  3. Same result. Both print 823230245000 because they store the same instant.
  4. Unit. The value is milliseconds since the Unix epoch — not a formatted date string.

Example 2 — valueOf() Equals getTime()

Confirm both methods return the same number for the same Date.

JavaScript
const d = new Date(0); // epoch

console.log(d.valueOf());  // 0
console.log(d.getTime());  // 0
console.log(d.valueOf() === d.getTime()); // true
Try It Yourself

How It Works

  1. Start at the epoch. new Date(0) is midnight UTC on Jan 1, 1970.
  2. Read with valueOf(). Zero milliseconds after the epoch → 0.
  3. Read with getTime(). Same internal value → also 0.
  4. They match. MDN treats them as functionally equivalent for Date.

Example 3 — Subtract Two Dates for Elapsed ms

Subtraction coerces each Date to a number (via the value-of path).

JavaScript
const a = new Date(Date.UTC(2026, 0, 1));
const b = new Date(Date.UTC(2026, 0, 2));

console.log(b.valueOf() - a.valueOf()); // 86400000
console.log(b - a);                     // 86400000 (1 day in ms)
Try It Yourself

How It Works

  1. Two UTC midnights. Jan 1 and Jan 2, 2026 — one day apart.
  2. Subtract the numbers. b.valueOf() - a.valueOf() is 86_400_000 ms.
  3. Or subtract the Dates. b - a coerces both sides to numbers and gets the same result.
  4. Why it helps. Epoch ms make duration math simple — divide by 1000 for seconds if needed.

Browser & Runtime Support

Date.prototype.valueOf() has been in JavaScript since ES1. It is Baseline and works in every modern browser and Node.js — no polyfill needed.

✓ Baseline · ES1

Date.prototype.valueOf()

Supported everywhere Date exists: Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions.

99% Universal API
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.valueOf() Excellent

Bottom line: Safe to use in any environment. Focus on equivalence with getTime() and NaN for invalid Dates. See also the MDN valueOf() reference.

Frequently Asked Questions

A number: milliseconds since January 1, 1970 00:00:00 UTC for that Date. It returns NaN if the Date is invalid. It does not return a Date object.
Yes for Date. valueOf() is functionally equivalent to getTime() — both return the same epoch milliseconds. Prefer getTime() when you want a clear “timestamp” call; valueOf() is the generic Object hook used in numeric coercion.
When a Date is coerced to a number — for example Number(date), +date, date - otherDate, or comparisons like dateA > dateB. Date also has Symbol.toPrimitive, which still uses valueOf() internally for the number path.
Compare the numbers: dateA.valueOf() < dateB.valueOf(). Subtracting two Dates (dateB - dateA) also works because both sides coerce to numbers.
NaN — the same as getTime() on an invalid Date. Check with Number.isNaN(date.valueOf()).
Date.now() is the current timestamp without a Date instance. valueOf() (or getTime()) reads the timestamp of an existing Date you already have.

Next: String Methods

Explore JavaScript string helpers after finishing Date methods.

String methods →

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.

12 people found this page helpful