Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uidatepicker 24hour formate in ios

I am Trying to assign the 24 hour formate to UIDATEPICKERVIEW 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.

Here is the my **Output**

like image 755
Jignesh Kanani Avatar asked Jan 29 '14 11:01

Jignesh Kanani


3 Answers

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"NL"];
[picker_alarm setLocale:locale];
like image 92
nerowolfe Avatar answered Oct 12 '22 06:10

nerowolfe


You can also use the storyboard to change time format to 24 hour.

Follow these steps:

  1. go to storyboard
  2. select you datePicker
  3. select attributes inspector
  4. Change "Locale" property to English(Europe)

enter image description here

and in your code use following snippet:

NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm"];
somelabel.text = [outputFormatter stringFromDate:_pickerDate.date];
like image 22
Jabbar Avatar answered Oct 12 '22 07:10

Jabbar


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

like image 1
Anil Varghese Avatar answered Oct 12 '22 08:10

Anil Varghese