鉴于此代码:
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyyMMdd"];
NSArray *datesArray = @[@"20130326", @"20130327", @"20130328", @"20130329", @"20130330", @"20130331", @"20130401"];
for (NSString *dateString in datesArray) {
NSDate *date = [dateFormatter dateFromString:dateString];
NSLog(@"date: %@", date);
}
这是我的时区(EST)的输出:
date: 2013-03-26 04:00:00 +0000
date: 2013-03-27 04:00:00 +0000
date: 2013-03-28 04:00:00 +0000
date: 2013-03-29 04:00:00 +0000
date: 2013-03-30 04:00:00 +0000
date: 2013-03-31 04:00:00 +0000
date: 2013-04-01 04:00:00 +0000
当我转到设置 -> 常规 -> 日期和时间,并将时区设置为约旦安曼 (GMT+3) 时,这是相同代码的输出:
date: 2013-03-25 22:00:00 +0000
date: 2013-03-26 22:00:00 +0000
date: 2013-03-27 22:00:00 +0000
date: (null)
date: 2013-03-29 21:00:00 +0000
date: 2013-03-30 21:00:00 +0000
date: 2013-03-31 21:00:00 +0000
为什么?