pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf

tps://developer.mozilla.org/favicon.ico" />

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

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 2015年7月.

Date 实例的 valueOf() 方法用于返回自纪元(即协调世界时 1970 年 1 月 1 日零点)以来的毫秒数。

尝试一下

const date1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5));

console.log(date1.valueOf());
// 预期输出:823230245000

const date2 = new Date("02 Feb 1996 03:04:05 GMT");

console.log(date2.valueOf());
// 预期输出:823230245000

语法

js
valueOf()

参数

无。

返回值

一个数字,表示该日期的时间戳,单位为毫秒。如果该日期无效,则返回 NaN

描述

valueOf() 方法是强制类型转换机制的一部分。由于 Date 拥有 [Symbol.toPrimitive]() 方法,当 Date 对象被隐式转换为数字时,该方法总是优先于 valueOf()。不过,Date.prototype[Symbol.toPrimitive]() 在内部仍会调用 this.valueOf()

Date 对象重写了 valueOf() 方法(该方法来自 Object)。Date.prototype.valueOf() 返回该日期的时间戳,其功能上等同于 Date.prototype.getTime() 方法。

示例

使用 valueOf()

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

规范

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

浏览器兼容性

参见

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy