保存在 FCM 数据库消息的时间戳上



所以我正在使用教程中的以下步骤来理解 fcm,我想知道是否有任何方法可以从发送/接收的消息中保存时间戳?

谷歌FCM教程第8页

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

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

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

time: new Date((.getTime((

示例代码:

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

最新更新