本文介绍了Flutter:将Firebase FieldValue.serverTimestamp()转换为DateTime对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

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对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:18