Date.prototype.valueOf()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
ThevalueOf() method ofDate instances returns the number of milliseconds for this date since theepoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.
In this article
Try it
const date1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5));console.log(date1.valueOf());// Expected output: 823230245000const date2 = new Date("02 Feb 1996 03:04:05 GMT");console.log(date2.valueOf());// Expected output: 823230245000Syntax
valueOf()Parameters
None.
Return value
A number representing thetimestamp, in milliseconds, of this date. ReturnsNaN if the date isinvalid.
Description
ThevalueOf() method is part of thetype coercion protocol. BecauseDate has a[Symbol.toPrimitive]() method, that method always takes priority overvalueOf() when aDate object is implicitlycoerced to a number. However,Date.prototype[Symbol.toPrimitive]() still callsthis.valueOf() internally.
TheDate object overrides thevalueOf() method ofObject.Date.prototype.valueOf() returns the timestamp of the date, which is functionally equivalent to theDate.prototype.getTime() method.
Examples
>Using valueOf()
const d = new Date(0); // 1970-01-01T00:00:00.000Zconsole.log(d.valueOf()); // 0Specifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-date.prototype.valueof> |