Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Date
  6. valueOf()

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.

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: 823230245000

Syntax

js
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()

js
const d = new Date(0); // 1970-01-01T00:00:00.000Zconsole.log(d.valueOf()); // 0

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-date.prototype.valueof

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp