如何从新的 `firebase.firestore.FieldValue.serverTimestamp()` 中获取 JavaScript 日期对象 [英] How to get a JavaScript Date object from the new `firebase.firestore.FieldValue.serverTimestamp()`
问题描述
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屋!