Notification:timestamp 屬性
注意:此功能在 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 |
瀏覽器相容性
載入中…