swift - 时间戳作为 "timestamp"保存到 Firestore 中是否正常?

标签 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 纪元以来的毫秒数的 long 吗?

最佳答案

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

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

关于swift - 时间戳作为 "timestamp"保存到 Firestore 中是否正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48234148/

相关文章:

swift - Instagram NSURL 使用 swift 实现

javascript - 返回从 array.push 中的 firebase foreach 完成的数组

firebase - flutter/FirebaseAuth : How can I autologin a user at app launch?

mysql - MySQL 中日期时间、日期和时间字段与时间戳的不同值

mysql - 从 unix 时间转换的问题

ios - NSManagedObject 不能符合 Swift 中的协议(protocol)

swift - 包含 XCode6 Beta 的路径

ios - 使用乘数的 Swift 约束使用尾随但不使用前导

ios - Swift - Firebase - 订单收集

c - (c/c++) 日/月/年 hh :ii:ss to unix timestamp