Firebase 的日期与时间戳 [英] Date vs Timestamp for Firebase
问题描述
您建议在日期时间和时间戳之间使用 Firebase 存储日期,为什么?
What would you recommend to store dates using Firebase between a datetime and a timestamp, and why?
推荐答案
使用时间戳,因为这与语言环境无关,并且不需要客户端之间的格式和解析协议.它也有点短.
Use a timestamp as this is locale-agnostic and does not require formatting and parsing agreements between clients. It's also a bit shorter.
此外,利用 Firebase.ServerValue.TIMESTAMP,而不是信任客户有他们的时钟设置正确.例如,如果客户的时钟差了 5 分钟,而您在聊天对话中使用了客户时间戳,然后渲染回消息,则显示的时间对于其他用户来说似乎是未来 5 分钟.
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.
这篇关于Firebase 的日期与时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!