如何在Firebase Unity中使用ServerValue.Timestamp?

问题描述 投票:0回答:1

我需要不变的服务器时间值。我正在使用Firebase和Unity3d。

我想使用Unity Firebase以字符串形式获取时间戳记值。

我更新了ServerValue.Timestamp。我在手机上更改了本地时间。然后我得到了更新的价值。我的应用返回了本地时间戳值,而不是Firebase数据库显示的ServerValue.Timestamp

如何在Firebase Unity中使用ServerValue.Timestamp

firebase unity3d
1个回答
0
投票

要获得准确的服务器时间,您需要以某种方式从服务器获取它。From the docsServerValue.Timestamp是:一个占位符值,用于由FirebaseDatabase服务器自动填充当前时间戳(自Unix纪元以来的时间,以毫秒为单位)。

如果将一些数据推送到包含该占位符作为其值的实时数据库中,则应将其读回,这应具有该写入的服务器时间。例如

database.update({ startedAt: Firebase.ServerValue.TIMESTAMP });

(检查this post输出]

您还可以估计clock skew,或使用Cloud Functions直接向服务器请求服务器时间。

© www.soinside.com 2019 - 2024. All rights reserved.