Notification:timestamp 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

注意:此功能在 Web Workers 中可用。

Notification 介面的只讀屬性 timestamp 返回一個數字,如 Notification() 建構函式的 timestamp 選項所指定。

通知的 timestamp 可以表示通知建立時事件的時間(自 1970 年 1 月 1 日 UTC 00:00:00 起以毫秒為單位),也可以是您希望與通知關聯的任意時間戳。例如,即將舉行的會議的 timestamp 可以設定為將來,而錯過的訊息的 timestamp 可以設定為過去。

表示時間戳的數字,以毫秒為單位的 Unix 時間

示例

以下程式碼片段會觸發一個通知;建立一個簡單的 options 物件,然後使用 Notification() 建構函式觸發通知。

js
const dts = Math.floor(Date.now());

const options = {
  body: "Your code submission has received 3 new review comments.",
  timestamp: dts,
};

const n = new Notification("New review activity", options);

console.log(n.timestamp); // Logs the timestamp

規範

規範
Notifications API
# dom-notification-timestamp

瀏覽器相容性

另見