javascript - 从 Firestore 数据库获取时间戳
问题描述
我在我的 Firestore 数据库中存储了一个时间戳,但是当我想获取时间戳时,我得到了一些我无法解释的数字。也许有一种特殊的技术可以从我不知道的 vuejs 应用程序中的 firestore 获取时间戳。
我的时间戳如下所示:
但是,如果我输入以下命令来获取我的时间戳:
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 的那个)
谢谢!!
解决方案
您看到的实际上是 Firestore 的Timestamp
class的内部表示。
如果您想获取自纪元以来的毫秒值,您可以调用toMillis()
时间戳对象。
所以像:
console.log(profile.date_of_birth.toMillis())
推荐阅读
- python - 对象可下标
- python-3.x - 使用 Python 图像库 (PIL) 保存 gif 图像时动画 GIF 图像像素化
- oracle-apex - 交互式网格中的可编辑字段
- amazon-web-services - 为什么网站对谷歌来说不可审计或可读?
- python - 圆形、矩形和方形的区别
- python-3.x - 如何使用python获取当前日期
- git - 在本地机器上更新特定的克隆分支
- reactjs - Material UI:是否可以将 makeStyle 样式放在单独的文件中?
- javascript - javascript转换日期格式
- java - 如何使用扫描仪输入读取带有斜杠“/”的 txt 文件并读取某些部分?