| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The valueOf() method of Date instances returns the number of milliseconds for this date since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.
const date1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5));
console.log(date1.valueOf());
// Expected output: 823230245000
const date2 = new Date("02 Feb 1996 03:04:05 GMT");
console.log(date2.valueOf());
// Expected output: 823230245000
valueOf()
None.
A number representing the timestamp, in milliseconds, of this date. Returns NaN if the date is invalid.
The valueOf() method is part of the type coercion protocol. Because Date has a [Symbol.toPrimitive]() method, that method always takes priority over valueOf() when a Date object is implicitly coerced to a number. However, Date.prototype[Symbol.toPrimitive]() still calls this.valueOf() internally.
The Date object overrides the valueOf() method of Object. Date.prototype.valueOf() returns the timestamp of the date, which is functionally equivalent to the Date.prototype.getTime() method.
const d = new Date(0); // 1970-01-01T00:00:00.000Z
console.log(d.valueOf()); // 0
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-date.prototype.valueof |
This page was last modified on Jul 10, 2025 by MDN contributors.
DategetDate()getDay()getFullYear()getHours()getMilliseconds()getMinutes()getMonth()getSeconds()getTime()getTimezoneOffset()getUTCDate()getUTCDay()getUTCFullYear()getUTCHours()getUTCMilliseconds()getUTCMinutes()getUTCMonth()getUTCSeconds()getYear()setDate()setFullYear()setHours()setMilliseconds()setMinutes()setMonth()setSeconds()setTime()setUTCDate()setUTCFullYear()setUTCHours()setUTCMilliseconds()setUTCMinutes()setUTCMonth()setUTCSeconds()setYear()toDateString()toISOString()toJSON()toLocaleDateString()toLocaleString()toLocaleTimeString()toString()toTemporalInstant()toTimeString()toUTCString()valueOf()[Symbol.toPrimitive]()Object/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |