Vis*_*mbo 5 timestamp firebase swift google-cloud-firestore
我是一名iOS编程新手。我正在创建一个与Firestore
. 在Firestore
我创建的集合中,每个文档都包含许多字段。
我在我的文档中添加了Timestamp
字段。当我创建模型时,xcode
我如何声明我的变量,Timestamp
因为我需要tableView
基于Timestamp
.
Timestamp
看起来是这样Firestore
的:
September 17, 2018 at 3:37:43 PM UTC+7
那么,我如何编写程序并获取当前的信息,Timestamp
如所示Firestore
这是编程中的:
struct RecentCallModel {
var call_answered: Bool?
var call_extension: String?
var call_type: String?
var details: String?
var duration: String?
var title: String?
// How can i declare as Timestamp
var timestamp: ???
init(call_answered: Bool, call_extension: String, call_type: String, details: String , duration: String, timestamp: String, title: String) {
self.call_answered = call_answered
self.call_extension = call_extension
self.call_type = call_type
self.details = details
self.title = title
}
}
Run Code Online (Sandbox Code Playgroud)
不熟悉 Firebase。但通常,在 iOS 中,我们将时间戳存储TimeInterval
为Double
.
class func getDateOnly(fromTimeStamp timestamp: TimeInterval) -> String {
let dayTimePeriodFormatter = DateFormatter()
dayTimePeriodFormatter.timeZone = TimeZone.current
dayTimePeriodFormatter.dateFormat = "MMMM dd, yyyy - h:mm:ss a z"
return dayTimePeriodFormatter.string(from: Date(timeIntervalSince1970: timestamp))
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9922 次 |
最近记录: |