Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Date 實例的 valueOf() 方法會回傳此日期自紀元(定義為 UTC 時間 1970 年 1 月 1 日午夜)以來的毫秒數。
無。
一個數字,表示此日期的時間戳(以毫秒為單位)。如果日期無效,則回傳 NaN。
valueOf() 方法是型別強制轉換協定的一部分。因為 Date 有一個 [Symbol.toPrimitive]() 方法,所以當 Date 物件被隱含地強制轉換為數字時,該方法總是優先於 valueOf()。然而,Date.prototype[Symbol.toPrimitive]() 內部仍然會呼叫 this.valueOf()。
Date 物件覆寫了 Object 的 valueOf() 方法。Date.prototype.valueOf() 會回傳日期的時間戳,這在功能上等同於 Date.prototype.getTime() 方法。
| ECMAScript® 2027 Language Specification # sec-date.prototype.valueof |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年8月18日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.