Date.prototype.valueOf()
valueOf()
方法返回一个 Date
对象的原始值。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
语法
dateObj.valueOf()
返回值
从1970年1月1日0时0分0秒(UTC,即协调世界时)到该日期的毫秒数。
描述
valueOf
方法返回以数值格式表示的一个 Date
对象的原始值,从1970年1月1日0时0分0秒(UTC,即协调世界时)到该日期对象所代表时间的毫秒数。
该方法的功能和 Date.prototype.getTime()
方法一样。
该方法通常在 JavaScript 内部被调用,而不是在代码中显式调用。
例子
使用 valueOf()
var x = new Date(56, 6, 17);
var myVar = x.valueOf(); // assigns -424713600000 to myVar
规范
规范版本 | 规范状态 | 注解 |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262) Date.prototype.valueOf |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) Date.prototype.valueOf |
Standard | |
ECMAScript (ECMA-262) Date.prototype.valueOf |
Living Standard |
浏览器兼容性
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.