Date vs Timestamp for Firebase

2019-01-19 01:08发布

问题:

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

回答1:

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.