英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论