I have a date in the format Tue, 29 May 2012 00:56:14 +0000 from an XML file, which is not under my control so the original format cannot be changed.
I was researching for how to create format strings for NSDateFormatter, found this page, and came up with the following code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE', 'dd' 'MMM' 'YYYY' 'HH':'mm':'ss' 'Z"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSDate *parsedDate = [dateFormatter dateFromString:date];
However, after parsing the date above, Tue, 29 May 2012 00:56:14 +0000, with this format string I get 2011-12-27 00:56:14 +0000. So the time is correct, but the date is all jumbled.
Could someone with some more knowledge of NSDateFormatter please explain why this isn’t working? To my knowledge the format string seems correct, but apparently it is not. Thanks!!
Your year format string should be lower case, ‘yyyy’