简体   繁体   中英

timestamp in firebase/firestore

When I save timestamp dates on firestore, it saves as a timestamp datatype. 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.

It seems very confusing. Is there a best practise about how to save and how to retrieve dates from 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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