Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Firestore数据库中最适合使用的时间戳格式是什么?_Ios_Swift_Firebase_Google Cloud Firestore_Timestamp - Fatal编程技术网

Ios Firestore数据库中最适合使用的时间戳格式是什么?

Ios Firestore数据库中最适合使用的时间戳格式是什么?,ios,swift,firebase,google-cloud-firestore,timestamp,Ios,Swift,Firebase,Google Cloud Firestore,Timestamp,我试图在Swift IOS中实现Firestore数据库时间戳,我试图找到最适合存储时间戳的方式,以便能够根据时间戳准确地获取数据 下面是我尝试使用的时间戳,但有时根据时间戳过滤器检索的结果并不准确 FieldValue.serverTimeStamp() Timestamp() let timestamp = Int(NSDate().timeIntervalSince1970) 代码 您到底面临什么错误,以及如何再次转换回时间戳?您能否分享一些代码或您在查找实际差异时面临的挑战。@So

我试图在Swift IOS中实现Firestore数据库时间戳,我试图找到最适合存储时间戳的方式,以便能够根据时间戳准确地获取数据

下面是我尝试使用的时间戳,但有时根据时间戳过滤器检索的结果并不准确

FieldValue.serverTimeStamp()

Timestamp()

let timestamp = Int(NSDate().timeIntervalSince1970)
代码


您到底面临什么错误,以及如何再次转换回时间戳?您能否分享一些代码或您在查找实际差异时面临的挑战。@SohilR.Memon,实际上,文档不是按照时间戳检索的,这是随机检索文档的主要问题,即使在使用“顺序”后也是如此功能你可以发布代码,比如你是如何检索的吗?@SohilR.Memon添加了代码如果你询问如何在Firestore中存储时间戳,它是包含的,如果你想使用你的应用程序生成它,它是包含的
let ref = Firestore.firestore().collection("messages").order(by: "timestamp", descending: true)

            ref.addSnapshotListener { (snapshot, error) in
                snapshot?.documentChanges.forEach({ (diff) in

                    let messageId = diff.document.documentID
                    let messageRef = Firestore.firestore().collection("messages")
                        .document(messageId)


                    messageRef.getDocument(completion: { (document, error) in
                        guard let dictionary = document?.data() as? [String : Any] else { return }

                        let message = Message(dictionary: dictionary)

                        print("we fetched this message \(message.text)")


                            self.messages.append(message)

                            DispatchQueue.main.async {
                                self.collectionView.reloadData()
                                let indexPath = IndexPath(item: self.messages.count - 1, section: 0)
                                self.collectionView.scrollToItem(at: indexPath, at: .bottom, animated: true)
                            }

                    })
                })
            }