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.

valueOf() メソッドは、 Date オブジェクトのプリミティブ値を返します。

試してみましょう

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

構文

js
valueOf()

返値

協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 から指定された日時までの間のミリ秒単位の数値。

解説

valueOf() メソッドは、 Date オブジェクトのプリミティブ値を数値型で返します。これは、1970 年 1 月 1 日 00:00:00 (UTC) からのミリ秒単位の数値です。

このメソッドは、Date.prototype.getTime() メソッドと機能的に同等です。

このメソッドは、JavaScript によって内部的に呼ばれるものであり、コード内で明示的に呼ばれることはありません。

valueOf() の使用

js
const x = new Date(56, 6, 17);
const myVar = x.valueOf(); // myVar に -424713600000 を代入

仕様書

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
valueOf

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報