将时间戳作为“时间戳”保存到Firestore中是正常的吗?

时间:2018-01-12 21:20:21

标签: swift firebase unix-timestamp google-cloud-firestore

我正在保存服务器值时间戳,如下所示:

let data : [String: Any] = ["userId": 9,
                            "name": "Elon Musk",
                            "timeCreated": ServerValue.timestamp()]

 let doc = firestore.collection("orders").document()
 doc.setData(data){ (error) in

 }

在查看Firestore时,虽然我看到了这一点:

enter image description here

这是正常的吗?难道不应该包含自Unix Epoch以来的毫秒数吗?

2 个答案:

答案 0 :(得分:6)

您正在使用服务器时间戳的实时数据库概念,即ServerValue.timestamp。它本质上是一个包含您显示的值的字典:{'.sv': 'timestamp'}。这与Firestore不兼容。

相反,您希望使用Firestore的服务器时间戳概念,即FieldValue.serverTimestamp()。另请参阅documentation here中的最后一个示例。

答案 1 :(得分:0)

不,这似乎不正常。这是我使用ServerValue.timestamp()时得到的。 enter image description here