Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add AM/PM to datepicker?

My UIDatePicker is set to UIDatePickerModeTime but on the apple documentation it says The date picker displays hours, minutes, and (optionally) an AM/PM designation. The exact items shown and their order depend upon the locale set. An example of this mode is [ 6 | 53 | PM ].. How do i add AM/PM because on my device, those aren't options and it instead uses a 24 hour clock?

like image 458
Andrew Avatar asked Jan 27 '11 22:01

Andrew


2 Answers

This will depend on the settings of the user. If you go to Settings -> General -> Date & Time. there is a "24-Hour" time switch, and based on that users will have the AM/PM indicator on your picker.

like image 81
phi Avatar answered Sep 19 '22 17:09

phi


Unfortunately UIDatePicker doesn't have an option for that; it always respects the device option of 12-hour or 24-hour time.

If you must have an AM/PM component you may have to go with a custom UIPickerView instead, and build an NSDate out of its components manually.

like image 25
BoltClock Avatar answered Sep 18 '22 17:09

BoltClock