如何从新的 `firebase.firestore.FieldValue.serverTimestamp()` 中获取 JavaScript 日期对象 [英] How to get a JavaScript Date object from the new `firebase.firestore.FieldValue.serverTimestamp()`

查看:22
本文介绍了如何从新的 `firebase.firestore.FieldValue.serverTimestamp()` 中获取 JavaScript 日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase Firestore 最近

Firebase Firestore recently changed how they manage timestamps, and I'm unable to retrieve a date object from the timestamp.

How do I get a date object from the new firebase.firestore.FieldValue.serverTimestamp()?

解决方案

You just need to do this:

yourFirestoreTimestamp.toDate()

If you look at the Timestamp object in the console you'll see that .toDate() is a function available by default on each Timestamp.

--

However, please note that when you haven't synced with Firestore yet FieldValue.serverTimestamp() gives nothing of value.

Only after you have synced with Firestore and the data is fetched again, the prop will be changed from serverTimestamp → to Timestamp

You'll also see much more information saved in a Timestamp object:

这篇关于如何从新的 `firebase.firestore.FieldValue.serverTimestamp()` 中获取 JavaScript 日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆