gpt4 book ai didi

javascript - 保存 FCM 数据库消息的时间戳

转载 作者:行者123 更新时间:2023-12-03 04:36:21 25 4
gpt4 key购买 nike

因此,我正在使用教程中的以下步骤来了解 fcm,我想知道是否有办法保存发送/接收消息中的时间戳?

Google FCM Tutorial Page 8

 this.messagesRef.push({
name: currentUser.displayName,
text: this.messageInput.value,
photoUrl: currentUser.photoURL || '/images/profile_placeholder.png'
})

正如您在此示例代码中所看到的,我推送了名称、文本和 photoUrl,但我还想要时间。

最佳答案

使用 getTime() 方法,它返回 1970 年 1 月 1 日午夜到指定日期之间的毫秒数。

时间:new Date().getTime()

示例代码:

this.messagesRef.push({
name: currentUser.displayName,
text: this.messageInput.value,
photoUrl: currentUser.photoURL || '/images/profile_placeholder.png',
time: new Date().getTime()
})

关于javascript - 保存 FCM 数据库消息的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43275500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com