看看这次在我的数据库中如何(我使用的是 parse.com):
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:" }
更多查看它在应用程序中的外观:
会发生什么?
最佳答案
“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"
}
关于ios - 不同时间数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024980/