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 GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
now

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

相關資源