To use 12-hour format for parsing, it seems NSDateFormatter
needs any 12-hour locale.
I don't know this is a kind of bug or not though.
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"es_US"]];
[dateFormatter setDateFormat:@"hh:mm:a MM/dd/yyyy"];
NSDate *date = [dateFormatter dateFromString:@"09:21:am 07/22/2014"];
To find 12-hour format locale, this code helps:
NSArray *locales = [NSLocale availableLocaleIdentifiers];
for(NSString *locale in locales) {
NSString *fmt = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale localeWithLocaleIdentifier:locale]];
NSLog(@"%10s:%@", [locale UTF8String], fmt);
}
see this answer