从 Firestore 数据库获取时间戳

时间:2021-02-16 15:58:35

标签: javascript vue.js google-cloud-firestore timestamp

我在我的 firestore 数据库中存储了一个时间戳,但是当我想获取时间戳时,我得到了一些我无法解释的数字。也许有一种特殊的技术可以从我不知道的 vuejs 应用程序中的 firestore 中获取时间戳。

我的时间戳如下所示:

Timestamp

但是如果我输入以下命令来获取我的时间戳:

let ref = db.collection('profile').doc('profile_data')
ref.get().then(snapshot => {
  profile = snapshot.data()
  profile.id = snapshot.id
}).then( () => {
  console.log(profile.date_of_birth)
})

我得到以下输出: 063147682800.000000000 与时间戳无关。 有人知道如何从我的 firestore 数据库中获取时间戳,以便我得到以下结果:1012086000000(这是我用来设置 date_of_birth 的那个)

谢谢!!

1 个答案:

答案 0 :(得分:0)

您所看到的实际上是 Firestore 的 Timestamp class 的内部表示。

如果您想获取自纪元以来的毫秒数,您可以在时间戳对象上调用 toMillis()

比如:

console.log(profile.date_of_birth.toMillis())
相关问题