此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in English Always switch to English

Event.timeStamp

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

說明

回傳事件建立的時間(單位是毫秒;從 epoch 開始計算)。

Syntax

event.timeStamp

範例

var number = event.timeStamp;

下面是一個較為完整的範例:

html
<html>
  <head>
    <title>timeStamp example</title>

    <script type="text/javascript">
      function getTime(event) {
        document.getElementById("time").firstChild.nodeValue = event.timeStamp;
      }
    </script>
  </head>

  <body onkeypress="getTime(event)">
    <p>Press any key to get the current timestamp for the onkeypress event.</p>
    <p>timeStamp: <span id="time">-</span></p>
  </body>
</html>

注意

這個 property 僅在瀏覽器支持該事件才會有用。

詳細資料