2014-09-01 68 views
-2

簡單的一個正在擾亂我,無法解決。我希望將當前的UTC轉換爲一串數字,但時間不對?當它的00小時它顯示爲10 ..空間在那裏只是爲了更容易閱讀。NSDate到NSString有時間錯誤?

登錄:

2014-09-01 10:24:16.337 MyApp[44834:60b] 2014-09-01 00:24:16 +0000 
2014-09-01 10:24:16.339 MyApp[44834:60b] 20140901 102416 

代碼:

NSDate *currentDate = [[NSDate alloc] init]; 
NSLog(@"%@", currentDate); 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyyMMdd HHmmss"]; 
NSString *currentDateString = [dateFormatter stringFromDate:currentDate]; 
NSLog(@"%@", currentDateString); 
+0

不,這不是錯誤 2014-09-01 00:24:16 +0000是GMT + 0當前時間+ 0 是您當前的時區+10? http://stackoverflow.com/questions/6229024/nsdate-format-outputting-wrong-date – 2014-09-01 00:36:44

回答

1

要創建的NSDate的對象是UTC,但是您創建的日期格式是使用系統/本地時區,因此時間差。

+0

固定爲:[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; – veggyaurus 2014-09-01 01:03:54