uidatepicker 24hour formate in ios
10,682
Solution 1
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"NL"];
[picker_alarm setLocale:locale];
Solution 2
You can also use the storyboard to change time format to 24 hour.
Follow these steps:
- go to storyboard
- select you datePicker
- select attributes inspector
- Change "Locale" property to English(Europe)
and in your code use following snippet:
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm"];
somelabel.text = [outputFormatter stringFromDate:_pickerDate.date];
Solution 3
You cannot force the date picker to show 24 hours time. That depends on the locale
property
Doc says:
UIDatePickerModeTime, // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM)
[datePicker setLocale:[NSLocale systemLocale]];
For testing this change the system time to 24hour mode. And check the picker in simulator
![Jignesh Kanani](https://i.stack.imgur.com/vsqrh.jpg?s=256&g=1)
Author by
Jignesh Kanani
Updated on June 06, 2022Comments
-
Jignesh Kanani about 2 years
I am Trying to assign the
24 hour
formate toUIDATEPICKERVIEW
but i have not exactly idea to implement it.in my view.h file
@property(nonatomic,retain) IBOutlet UIDatePicker *picker_alarm;
in my view.m file
picker_alarm.date=[NSDate date];
in my .xib file
i have taken uidatepicker and its Mode Property to Time in viewcontroller.