Date.now()
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.now()
方法回傳自 1970/01/01 00:00:00 UTC 起經過的毫秒數。
格式
var timeInMs = Date.now();
回傳值
一個代表由經 UNIX 紀元起經過的毫秒數值(Number
)。
描述
由於 now()
是 Date
的靜態方法,你只能用 Date.now()
的方式呼叫它。
補完
這個函數是 ECMA-262 第 5 版的標準。 對於未更新支援此方法的引擎,可以利用底下的程式補上:
js
if (!Date.now) {
Date.now = function now() {
return new Date().getTime();
};
}
規範
Specification |
---|
ECMAScript Language Specification # sec-date.now |
瀏覽器相容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
now |
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.
相關資源
Performance.now()
— 提供亞毫秒級的時間戳記,作為評估網頁效能的解決方案。console.time()
/console.timeEnd()