日期与Firebase的时间戳 [英] Date vs Timestamp for Firebase

查看:144
本文介绍了日期与Firebase的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否建议在datetime和时间戳之间使用 Firebase 存储日期,以及为什么?

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

推荐答案

使用时间戳,因为这是locale-agnostic,不需要客户端之间的格式化和解析协议。它也有点短。

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 incorrectly. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆