此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Date.prototype.getMilliseconds()

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

getMilliseconds() 方法根据本地时间,返回一个指定的日期对象的毫秒数。

尝试一下

const moonLanding = new Date("July 20, 69 00:20:18");
moonLanding.setMilliseconds(123);

console.log(moonLanding.getMilliseconds());
// Expected output: 123

语法

js
getMilliseconds()

参数

描述

getMilliseconds() 方法返回一个 0 到 999 的整数。

示例

示例:使用getMilliseconds方法

下例中,将当前时间的毫秒数赋值给变量 ms

js
var ms;
Today = new Date();
ms = Today.getMilliseconds();

规范

规范
ECMAScript® 2027 Language Specification
# sec-date.prototype.getmilliseconds

浏览器兼容性

参见