2015-08-15 25 views
0

看看這個時候在我的數據庫(我使用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

會發生什麼情況?

回答

1

「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

+1

TKS !!!!!完善! –

+0

@RenêLimade nada –

0

好吧只是一個猜測,但...

解析日期通常是UTC。如果您設置不同的時區,則應更改日期的小時部分...

相關問題