NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzz"];
NSString *dateString = @"Tue, 08 Jun 2010 17:00:00 EDT";
NSDate *eventDate = [dateFormatter dateFromString:dateString];
In this case the eventDate object is nil. Can somebody clue me in? This code used to work.
UPDATE:
Can’t talk about why this doesn’t work due to NDA. Suffice it to say, when iOS 4 is out I will post the answer to my own question.
The answer to this question is the following:
I was using the wrong date format string:
when it should have been:
The part about iOS 4 and NDA was that I thought I had to use the
NSDateFormattermethoddateFormatFromTemplate:options:locale:which would have looked like this:However, that method should only be used when you want to DISPLAY the date to a user of unknown locale. In my case, I knew exactly what the date format was going to look like and I was trying to PARSE the date string so that I could store it in CoreData. Therefore, that method wasn’t useful.
Bonus bookmark: Read this table very carefully and you will definitely figure out what the problem is… Unicode date formats should follow these specifications: http://unicode.org/reports/tr35/tr35-6.html#Date_Field_Symbol_Table
TL;DR The format string was wrong. D’oh!