如何从日期创建日期字符串而不包括任何夏令时?

时间:2012-11-02 15:03:19

标签: objective-c date iso8601

NSString* dateString = @"2012-04-01T15:37:53Z";

ISO8601DateFormatter *dateFormat = [[ISO8601DateFormatter alloc] init];
[dateFormat setIncludeTime:YES];
NSTimeZone *utcTimeZone = [NSTimeZone timeZoneWithName:@"UTC"];

NSDate* date = [dateFormat dateFromString:dateString timeZone:&utcTimeZone];

STAssertEqualObjects([dateFormat stringFromDate:date timeZone:utcTimeZone], dateString, nil, nil);

上述测试失败,

  

'2012-04-01T16:37:53Z'应该等于'2012-04-01T15:37:53Z'

不确定为什么stringFromDate:date返回的NSString为1小时后,因为两个日期都使用UTC。

1 个答案:

答案 0 :(得分:1)

there is a bug的#stringFromDate中看起来像has been resolved in a fork