NSDateFormatter
给了我几乎正确的结果。差别只有4分钟。哪里……从哪里来的??!(时区偏移为 18000 秒 = 正好 5 小时!)(iOS 6)
NSDate* n = ...;
NSDateFormatter *gmtFormatter = [[NSDateFormatter alloc] init];
[gmtFormatter setDateStyle:NSDateFormatterNoStyle];
[gmtFormatter setTimeStyle:NSDateFormatterShortStyle];
DLog(@"n = %@, formatted to = %@, timeZone = %@", n, [gmtFormatter stringFromDate:n], gmtFormatter.timeZone);
[gmtFormatter release];
结果:
2013-01-25 14:49:29.224 字典 [1321:907] n = 0001-01-01 18:57:02 +0000,格式化为 = 下午 2:01,时区 = America/New_York (EST) 偏移量 -18000