views:

932

answers:

4

How to disable or hide AM/PM in UIDatePicker from code / interface builder? I want to have 24 hours time picker mode in UIDatePicker. Please help

+1  A: 

AFAIK you can't (within limits of SDK). The AP/PM will disappear if the user chooses to use 24-hour format. Make your own UIPickerView in case this is important.

KennyTM
A: 

According to the documentation you should be able to set the locale property of UIDatePicker to a locale that uses a 24 hrs format.

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"da_DK"];
[datePicker setLocale:locale];
[locale release];

Alas there is a bug causing both simulator and device to continue to layout the date picker according to the users international preferences.

As you suggest, you have to roll your won date picker to be able to display a 24 hrs picker.

Niels Castle
I tried en_GB and dk_DK locale does not work in simulator nor in device. But i noticed if u set 24 hrs format in iphone settings then UIDatepicker displays 24 hr time.So should I make my own UIPickerView or is there a way to acheive this?
Binay Shrestha
I was wrong in my original answer (now updated) neither device nor simulator works. A bug report has been filed with Apple.For now I'd do as you suggest - roll your own.
Niels Castle
It is not a bug, you are only changing a language, while in reality it depends on country settings.
Vladimir Grichina
A: 

I also reported this bug to Apple, so we'll see how long it takes for them to fix it... :)

In the meantime, can you post some example code for how you "rolled your own" UIDatePicker? Thanks.

A: 

As answered here http://stackoverflow.com/questions/1151335/can-i-localize-a-uidatepicker/2265984#2265984 and here http://stackoverflow.com/questions/2894161/uidatepicker-problem-localizing/2918507#2918507, the picker display depends on country settings, not on language settings.

In your example you are changing the language locale only.

Vladimir Grichina