简体   繁体   English

firebase/firestore 中的时间戳

[英]timestamp in firebase/firestore

When I save timestamp dates on firestore, it saves as a timestamp datatype.当我在 Firestore 上保存时间戳日期时,它会保存为时间戳数据类型。 But when I retrieve the data into React, sometimes it is retrieved as a timestamp and I can convert it to JS date using toDate() but other times is retrieved as {_seconds, _nanoseconds} and I need to convert it manually.但是当我将数据检索到 React 中时,有时它会作为时间戳检索,我可以使用toDate()将其转换为 JS 日期,但其他时候检索为{_seconds, _nanoseconds} ,我需要手动转换它。

It seems very confusing.这似乎很混乱。 Is there a best practise about how to save and how to retrieve dates from Google Firestore?是否有关于如何保存以及如何从 Google Firestore 中检索日期的最佳做法? Thanks谢谢

The only way to store dates in Firestore is through the Timestamp, you could store them through Strings, but it would be a huge pain to convert it back to Date so there really isn't any other better way to do it, unfortunately.在 Firestore 中存储日期的唯一方法是通过时间戳,您可以通过字符串存储它们,但是将其转换回Date将是一个巨大的痛苦,因此不幸的是,真的没有其他更好的方法可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM