Date.prototype.setUTCMilliseconds()
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.
setUTCMilliseconds()
方法会根据世界时来设置指定时间的毫秒数。
尝试一下
const date1 = new Date("2018-01-24T12:38:29.069Z");
console.log(date1.getUTCMilliseconds());
// Expected output: 69
date1.setUTCMilliseconds(420);
console.log(date1.getUTCMilliseconds());
// Expected output: 420
语法
dateObj.setUTCMilliseconds(millisecondsValue)
参数
millisecondsValue
-
0 - 999 之间的数值,代表毫秒数。
返回值
返回更新后的时间距 1970 年 1 月 1 日 00:00:00 (UTC) 的毫秒数。
描述
示例
使用 setUTCMilliseconds() 方法
js
var theBigDay = new Date();
theBigDay.setUTCMilliseconds(500);
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-date.prototype.setutcmilliseconds |
浏览器兼容性
BCD tables only load in the browser