为NSDateFormatter的dateFromString调用返回nil

时间:2010-04-05 04:58:56

标签: objective-c nsdateformatter

我在以下代码中为日期变量返回nil。我发现日期格式没有任何问题,有人可以帮忙吗?

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEE MMM dd HH:mm:ss zzz yyyy"];

NSString *dateString = [[NSString alloc] initWithFormat:@"%@", @"Mon Apr 05 04:37:28 UTC 2010"];
NSDate *date = [formatter dateFromString:dateString];

1 个答案:

答案 0 :(得分:2)

尝试

NSDate *date = [formatter dateFromString:@"Mon Apr 05 04:37:28 GMT 2010"];

NSDate *date = [formatter dateFromString:@"Mon Apr 05 04:37:28 +0000 2010"];