问题描述
我有
FieldValue.serverTimestamp()
我找不到在 Flutter 中将此时间戳转换为 DateTime
对象的方法.有什么办法吗?或者任何其他使用 firebase 的 API 调用?
I couldn't find a way to convert this timestamp to DateTime
object in Flutter. Is there any way to do it? Or any other API call using firebase?
推荐答案
FieldValue.serverTimestamp()
不是时间戳,而是所谓的哨兵——发送到服务器的标记,然后服务器识别并解释以写入当前时间戳.这意味着无法将 FieldValue.serverTimestamp()
转换为客户端上的时间戳.
The FieldValue.serverTimestamp()
is not a timestamp, but a so-called sentinel - a marker that gets sent to the server, that the server then recognizes and interprets to write the current timestamp. That means there is no way to convert FieldValue.serverTimestamp()
to a timestamp on the client.
您可以做的是写入 FieldValue.serverTimestamp()
到服务器上的文档,并观察写入该文档的值.该值将是一个有效的时间戳.
What you can do is write FieldValue.serverTimestamp()
to a document on the server, and observe the value that is written to that document. This value will be a valid timestamp.
这篇关于Flutter:Firebase FieldValue.serverTimestamp() 到 DateTime 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!