更新时间:2023-11-06 17:54:40
我也有这个问题,我不确定这是Apple代码中的API错误,还是我缺乏理解,但我通过在我的日期字符串中使用小时偏移来解决这个问题。
I've had this problem also, I'm not sure if it's a API bug within Apple's code, or my lack of understanding, but I've worked around it by using hour offsets in my date strings.
如果您将示例中的代码更改为:
If you change the code in your example to:
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSString* str = @"2009-08-11T06:00:00.000-0700"; // NOTE -0700 is the only change
NSDate* date = [df dateFromString:str];
它现在将解析日期字符串。当然-0700小时是我的抵消,你必须把它改成你的。希望这会有所帮助。
It will now parse the date string. Of course the -0700 hours is my offset, you'd have to change it to yours. Hope this helps.