此 setUTCSeconds()
方法为一个依据国际通用时间的特定日期设置秒数。
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.setUTCSeconds(secondsValue[, msValue])
参数
-
secondsValue
- 一个在0到59之间的整数,表示秒数。
-
msValue
- 可选参数。一个0到999之间的数字,代表毫秒数。
返回值
一个毫秒数,表示从国际通用时间1970年00:00:00到设置的时间值之间的时间跨度。
描述
如果你没有设置msValue参数的值, 那么返回的值来自getUTCMilliseconds()
方法。
如果你指定的值超出了范围, setUTCSeconds()
因此会更新Date
对象中的分钟数会增加1, 并且秒数会变成40.
示例
使用 setUTCSeconds()
var theBigDay = new Date(); theBigDay.setUTCSeconds(20);
规范
说明 | 状态 | 备注 |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | 初始化设定. 从 JavaScript 1.3继承. |
ECMAScript 5.1 (ECMA-262) Date.prototype.setUTCSeconds |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) Date.prototype.setUTCSeconds |
Standard | |
ECMAScript Latest Draft (ECMA-262) Date.prototype.setUTCSeconds |
Draft |
浏览器兼容性
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.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
setUTCSeconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support