ios - 不同时间数据库

标签 ios swift date parse-platform

看看这次在我的数据库中如何(我使用的是 parse.com):

2015-08-11 18:00:00 +0000

2015-08-11 18:00:00 +0000

我的代码:

// Data no detalhamento
var endDateFormatter = NSDateFormatter()
endDateFormatter.locale = NSLocale(localeIdentifier: "pt_BR")
endDateFormatter.dateFormat = "E, dd MMM yyyy HH:mm:ss"
endDateFormatter.timeZone = NSTimeZone.localTimeZone()

let endDateStr = endDateFormatter.stringFromDate(eventObj[EVENTS_END_DATE] as! NSDate)



if endDateStr != "" {  endDateLabel.text = "Sorteio: \(endDateStr)"
} else { endDateLabel.text = "Sorteio:"  }

更多查看它在应用程序中的外观:

enter image description here

会发生什么?

最佳答案

“2015-08-11 18:00:00 +0000”表示 UTC 时间下午 6 点。巴西的本地时间偏移量为负 3 小时,这就是为什么您的本地时间日期显示为 15:00(下午 3 点)。

let endDateString = "2015-08-11 18:00:00 +0000"

let endDateFormatter = NSDateFormatter()
endDateFormatter.calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierISO8601)
endDateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
endDateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
endDateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss xx"
if let dateFromString = endDateFormatter.dateFromString(endDateString) {
    print(dateFromString)   // "2015-08-11 18:00:00 +0000"
}

enter image description here

关于ios - 不同时间数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024980/

相关文章:

ios - iPhone 消息过滤器扩展无法正常工作

ios - 当我的应用程序返回前台时调用我的 View 中的方法

ios - 将图像存储到 CoreData - Swift

php - 计算两个日期之间的工作时间

javascript - 为什么我无法将毫秒从 C# 转换为 JavaScript 日期对象?

mysql - 获取 mysql 中日期的 unix_timestamp

ios - UICollectionView 未完全显示单元格。最后一个单元格没有完全显示

ios - 我希望我的 UILabel 遵循我的 UISlider 值

ios - Alamofire POST 错误 token - Swift

ios - Swift 3.0 - 根据 2 个不同枚举的每种情况调用函数