获取Firebase服务器时间的方法是什么?

huangapple go评论81阅读模式
英文:

How to get Firebase serverTime?

问题

对于安卓:

我们可以通过以下方式获取服务器时间:

Timestamp.now().getSeconds();

然后对于 iOS,我们可以通过以下方式获取服务器时间:

Timestamp.init().seconds

我的问题:
Timestamp.now().getSeconds(); 的长度是13个字符,而 Timestamp.init().seconds 只有10个字符长。

在 xCode 上有没有办法获取13个字符长的服务器时间?

英文:

For android:
We can get serverTime by:

Timestamp.now().getSeconds();

Then for iOS we can get serverTime by:

Timestamp.init().seconds

My problem:
Timestamp.now().getSeconds(); is 13 characters long, Timestamp.init().seconds is only 10 characters long.

Is there a way to get the 13 characters serverTime on xCode?

答案1

得分: 2

这些代码行根本没有获取服务器时间。它们获取的是设备上的本地时间,以 Timestamp 对象的形式转换为秒。没有直接且准确获取服务器时间的 API。

秒数是一个数字。它不是像字符串那样以“字符数”来衡量的。我建议阅读Timestamp 的 API 文档,以更好地理解你正在调用的方法的含义,并选择符合你特定需求的方法。你可能需要进行一些转换来获得你想要的结果,所以要明确了解你所获取的内容。

英文:

Those lines of code are not getting server time at all. They're getting local time on the device, in the form of a Timestamp object, converted to seconds. There's no API to get server time directly and accurately.

The number of seconds is a number. It's not measured in "number of characters" like a string. I suggest reading the API documentation for Timestamp to better understand the meaning of the methods you're calling, and choose the one that meets your specific needs. You might have to do some conversions to get what you want, so be clear to understand what you're getting.

答案2

得分: 1

我自己解决了。

Swift中有:

ServerValue.timestamp()

只是没想到,不知为何。只需要将其写入服务器即可。

英文:

I figured it out myself.

Swift has:

ServerValue.timestamp()

Just didn't think of it, for some reason. Only needed it to be written to the server.

huangapple
  • 本文由 发表于 2020年5月30日 06:40:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/62095590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定