2014-09-01 65 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