如何从新的firebase.firestore.FieldValue.serverTimestamp()获取JavaScript Date对象 [英] How to get a JavaScript Date object from the new `firebase.firestore.FieldValue.serverTimestamp()`
问题描述
Firebase Firestore最近更改了时间戳管理方式,并且我无法从时间戳中检索date
对象.
Firebase Firestore recently changed how they manage timestamps, and I'm unable to retrieve a date
object from the timestamp.
如何从新的firebase.firestore.FieldValue.serverTimestamp()
获取日期对象?
How do I get a date object from the new firebase.firestore.FieldValue.serverTimestamp()
?
推荐答案
您只需要这样做:
yourFirestoreTimestamp.toDate()
如果您在控制台中查看Timestamp
对象,则会看到.toDate()
是默认情况下在每个Timestamp
上可用的功能.
If you look at the Timestamp
object in the console you'll see that .toDate()
is a function available by default on each Timestamp
.
-
但是,请注意,当您尚未与Firestore同步时
FieldValue.serverTimestamp()
没有任何价值.
However, please note that when you haven't synced with Firestore yet
FieldValue.serverTimestamp()
gives nothing of value.
只有在与Firestore同步并再次获取数据之后,道具才会从serverTimestamp
→更改为Timestamp
Only after you have synced with Firestore and the data is fetched again, the prop will be changed from serverTimestamp
→ to Timestamp
您还将看到保存在Timestamp
对象中的更多信息:
You'll also see much more information saved in a Timestamp
object:
这篇关于如何从新的firebase.firestore.FieldValue.serverTimestamp()获取JavaScript Date对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!