I can’t figure out why the next piece of code only works when I set the Region Format to United States.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"];
NSDate *date = [dateFormatter dateFromString:currentFeedPubDate];
NSLog(@"%@", date);
Otherwise it returns “(null)”.
Can anyone help me find out why ?
As Krizz already noted, the issue is that the localized names won’t match. For example, if you feed it a date like
Sun, 15 Jan 2012 22:52:00 GMT+1and the phone is currently set to German, it won’t recognizeSunas it would look for an abbreviation of a German weekday name but won’t find one.If you know in which locale format the input string will be you can (and need to) force the locale on your date formatter like this: