I am making a custom TimePicker from a UIPickerView. I have it working great except when it comes to displaying the hours. I want it to function just like the UIDatePicker
so that it follows the users Locale
setting. If they have French selected, the time should display in 24 hour format. If they have US it should display in 12 hour format.
I have an array hoursArray
that goes from 0 - 23. I then run this code to convert it to the needed format. However it is not wanting to change to 24 hour format if that option is set in the Settings -> International section
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale currentLocale]];//[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[dateFormatter setDateFormat:@"H"];
NSDate *tempDate = [dateFormatter dateFromString:[hoursArray objectAtIndex:row]];
[dateFormatter setDateFormat:@"h"];
return [dateFormatter stringFromDate:tempDate];
I tried changing [dateFormatter setDateFormat:@"h"];
to [dateFormatter setDateFormat:@"H"];
since Apples doc says the users personal locale setting will override it, but this doesn't seem to be the case.
How do I get the dateFormatter
to follow the users locale setting properly?