不同的实时数据库
问题描述:
看看这个时候在我的数据库(我使用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"
}
答
好吧只是一个猜测,但...
解析日期通常是UTC。如果您设置不同的时区,则应更改日期的小时部分...
TKS !!!!!完善! –
@RenêLimade nada –