Reputation: 1394
I am trying to change locale for UIDatePicker like this:
picker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
It is working, but after setting locale the picker does not meet the system settings of time format. I mean 24hr/(AM/PM). What I am doing wrong?
Upvotes: 4
Views: 8937
Reputation: 3726
The marked answer is not quite correct if you want to support the time format desired by the user.
If you set the picker locale to the default (that of the device) the picker will use the 12/24 hr format of that particular locale. In the US this would be 12hr and in the UK for example this would be 24hr.
However, if the user changes their device manually to 12/24 your picker will not use this style.
If your picker is only using time and not date+time you can resolve this using a couple of approaches:
If you're using the date+time then you need to set a locale to that of the device to get the date in the right language and format but this will then ignore the time format set on the device.
Upvotes: 0
Reputation: 1359
You are not doing anything wrong. Date/time format is dictated by locale. And en_US uses 12hr AM/PM format: http://demo.icu-project.org/icu-bin/locexp?_=en_US
Upvotes: 0