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 |
浏览器兼容性
加载中…