我在以下代码中为日期变量返回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];
答案 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"];