现在我正在使用 swift 开发 IOS 应用程序,并以 Firebase.com 作为后端
首先我尝试通过这个函数来计算时间
var userHistoryForupdate = ["dealdate":FirebaseServerValue.timestamp()]
userHistoryRef.updateChildValues(userHistoryForupdate as [NSObject : AnyObject], withCompletionBlock: {
(error:NSError?, ref:Firebase!) in
if (error != nil) {
} else {
}
})
然后在其他 View 中我通过这个函数检索时间
var tempPubdate = self.pubDataArray[indexPath.row]["dealdate"] as! Double
dateFormatter.dateFormat = "dd MMM yy"
var dealDateAndTime = NSDate(timeIntervalSince1970: tempPubdate)
cell?.historyDate.text = "\(self.dateFormatter.stringFromDate(dealDateAndTime))"
我的手机显示
如你所见,我的日期是 38 年 1 月 23 日,而不是今天。
任何人都知道如何从 firebase 获取正确的日期,谢谢!
最佳答案
timeIntervalSince1970 需要秒,而 Firebase 的时间戳以毫秒为单位。
关于ios - Swift 从 Firebase ServerValue.timestamp() 得到错误的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30254991/