ios - Swift 从 Firebase ServerValue.timestamp() 得到错误的日期

标签 ios swift timestamp firebase

现在我正在使用 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))"

我的手机显示

enter image description here

如你所见,我的日期是 38 年 1 月 23 日,而不是今天。

任何人都知道如何从 firebase 获取正确的日期,谢谢!

最佳答案

timeIntervalSince1970 需要秒,而 Firebase 的时间戳以毫秒为单位。

关于ios - Swift 从 Firebase ServerValue.timestamp() 得到错误的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30254991/

相关文章:

ios - 从 URL 延迟获取图像

ios - 换行符不适用于 Swift 中的 txt 文件

json - Swift:过滤 TableView 中的结果,因此它不会从 JSON 返回重复项

ios - 什么时候调用父函数?

mysql - FROM_UNIXTIME 到 MySQL 返回错误日期

datetime - mysqldb 将时间戳数据转换为 None

ios - 在/服务器 url 中验证请求

ios - 如何捕获状态 - 比 BOOL 更灵活但比 NSString 更独特

swift - 检查 Parse.com 字段是否为 undefined/nil ?

java - 将时间戳排序为半小时 block