开发者

return nil for dateFromString call of NSDateFormatter

开发者 https://www.devze.com 2022-12-25 11:25 出处:网络
I am getting nil returned for the date variable in the below code. I can\'t find开发者_StackOverflow社区 any problem with the date format, can anyone help?

I am getting nil returned for the date variable in the below code. I can't find开发者_StackOverflow社区 any problem with the date format, can anyone help?

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];


Try

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

or

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

精彩评论

暂无评论...
验证码 换一张
取 消