Date.prototype.setMilliseconds()

Date 实例的 setMilliseconds() 方法根据当地时间更改该日期的毫秒数。

¥The setMilliseconds() method of Date instances changes the milliseconds for this date according to local time.

Try it

语法

¥Syntax

js
setMilliseconds(millisecondsValue)

参数

¥Parameters

millisecondsValue

0 到 999 之间的整数,表示毫秒。

返回值

¥Return value

就地更改 Date 对象,并返回其新的 timestamp。如果 millisecondsValueNaN(或获取 coercedNaN 的其他值,例如 undefined),则日期设置为 失效日期 并返回 NaN

¥Changes the Date object in place, and returns its new timestamp. If millisecondsValue is NaN (or other values that get coerced to NaN, such as undefined), the date is set to Invalid Date and NaN is returned.

描述

¥Description

如果你指定的数字超出预期范围,则 Date 对象中的日期信息将相应更新。例如,如果指定 1005,则秒数增加 1,并且使用 5 表示毫秒。

¥If you specify a number outside the expected range, the date information in the Date object is updated accordingly. For example, if you specify 1005, the number of seconds is incremented by 1, and 5 is used for the milliseconds.

示例

¥Examples

使用 setMilliseconds()

¥Using setMilliseconds()

js
const theBigDay = new Date();
theBigDay.setMilliseconds(100);

规范

Specification
ECMAScript Language Specification
# sec-date.prototype.setmilliseconds

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看