Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date vs Timestamp for Firebase

What would you recommend to store dates using Firebase between a datetime and a timestamp, and why?

like image 765
NSCoder Avatar asked Jun 14 '14 07:06

NSCoder


People also ask

What is the format of firestore timestamp?

Date and time in the Firestore are saved in their proprietary date format — called Timestamp. Firestore timestamp is just a simple object with two properties — seconds and nanoseconds, which apparently has some advantages over “classic” date format.

How do I get the date from firestore timestamp?

To convert a Firestore Timestamp into a Javascript date, just call . toDate() on the Timestamp.

How is date stored in firebase?

You can store the date as an epoch date. It's a long that you can get using your system time System. currentTimeMillis(); or by using the Firebase server time with their ServerValue. TIMESTAMP .

What is timestamp in firebase?

What is timestamp in firebase? A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one.


1 Answers

Use a timestamp as this is locale-agnostic and does not require formatting and parsing agreements between clients. It's also a bit shorter.

Furthermore, utilize Firebase.ServerValue.TIMESTAMP, rather than trusting the clients to have their clocks set correctly. If, for example, a client's clock is off by 5 minutes and you utilize the client timestamps in a chat conversation, then rendering back the messages, the time shown would appear to be 5 minutes in the future for other users.

like image 157
Kato Avatar answered Oct 20 '22 15:10

Kato