【问题标题】:Save on FCM database message's timestamp保存 FCM 数据库消息的时间戳
【发布时间】:2017-04-07 10:14:28
【问题描述】:

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

Google FCM Tutorial Page 8

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

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

【问题讨论】:

    标签: javascript firebase web firebase-cloud-messaging


    【解决方案1】:

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

    时间:新的 Date().getTime()

    示例代码:

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

    【讨论】:

    • 非常感谢。但是为什么我找不到这个方法?如果可能,发布您找到此方法的链接以及可能的其他方法
    • @Nick 这是一个 javascript 日期时间方法。只需参考以下链接w3schools.com/jsref/jsref_gettime.asp
    猜你喜欢
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    • 2014-05-25
    • 1970-01-01
    相关资源
    最近更新 更多