I had a weird issue today, I have the following code:
#define kApiDateFormat @"MM/dd/yyyy HH:mm:ss a"
...
+ (NSDate*)dateWithApiFormatString:(NSString*)dateString {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:kApiDateFormat];
return [dateFormat dateFromString:dateString];
}
The date i'm trying to format is 12/29/2014 12:00:00 AM
and my device's locale is es_CL
, searching on the internet I've found a solution, I needed to set the locale of the dateFormatter to en_US
like this:
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
So my question is the following... WHY?, I couldn't find any information explaining why I couldn't parse the date string to a date using my device's locale.
Thanks