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

浏览器兼容性

另见