swift语言中云Firestore服务器时间戳的等效数据类型是什么?

Vah*_*aji 4 timestamp firebase swift google-cloud-firestore

我有一个包含时间戳字段的数据模型createdAt.

struct Box {
    var title: String
    var createdAt: Timestamp

    var dictionary: [String : Any] {
        return [
            "title": title,
            "createdAt": createdAt
        ]
    }

// ...
Run Code Online (Sandbox Code Playgroud)

但是,我无法分配Firestore服务器时间戳.swift中云Firestore服务器时间戳的等效数据类型是什么?我在这里错过了一点吗?

let box = Box(title: title, createdAt: FieldValue.serverTimestamp());
Run Code Online (Sandbox Code Playgroud)

rba*_*win 10

当您回读Timestampfrom时Firestore,可以将其转换为Date对象:

if let timestamp = data["createdAt"] as? Timestamp {
    let date = timestamp.dateValue()
}
Run Code Online (Sandbox Code Playgroud)
/** Returns a new NSDate corresponding to this timestamp. This may lose precision. */
- (NSDate *)dateValue;
Run Code Online (Sandbox Code Playgroud)

Timestamp是一个FIRTimestamp返回如下的对象:

FIRTimestamp: seconds=1525802726 nanoseconds=169000000>

转换后.dateValue():

2018-05-08 18:05:26 +0000