Date.prototype.setMilliseconds()
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.
Date
实例的 setMilliseconds()
方法会根据本地时间设置一个日期对象的毫秒数。
尝试一下
const event = new Date("August 19, 1975 23:15:30");
console.log(event.getMilliseconds());
// Expected output: 0
event.setMilliseconds(456);
console.log(event.getMilliseconds());
// Expected output: 456
语法
js
setMilliseconds(millisecondsValue)
参数
millisecondsValue
-
一个在 0 到 999 之间的整数,表示毫秒数。
返回值
描述
如果指定的数字超出了合理范围,则 Date
对象的时间信息会被相应地更新。例如,如果指定了 1005,则秒数加 1,毫秒数为 5。
示例
使用 setMilliseconds()
js
const theBigDay = new Date();
theBigDay.setMilliseconds(100);
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-date.prototype.setmilliseconds |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
setMilliseconds |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on 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.