views:

355

answers:

1

I am getting nil returned for the date variable in the below code. I can't find 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];
+2  A: 

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