How to disable AM/PM in UIDatePicker

前端 未结 5 1823
青春惊慌失措
青春惊慌失措 2020-12-15 18:48

How to disable or hide AM/PM in UIDatePicker from code / interface builder?

I want to have 24 hours time picker mode in UIDatePicker. Pleas

5条回答
  •  失恋的感觉
    2020-12-15 19:28

    I know this is old... but I was looking into this recently and found this through some testing:

    [datePicker setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_FR"]];
    

    This basically tells me that the "language" is English (the "en" part) and "time style" is French (which is default 24hr time) (the "FR" part). I combined the two through trial and error and found that it was working for what I wanted, which was just to have a "Date and Time" picker that also picks in 24 hour time (no AM/PM section on the picker, in English text).

    The problem with this is, when you grab the date here, the locale may be wrong ->

    - (void)changeDate:(UIDatePicker *)sender {
    

    So do this to fix the locale in the date change selection part:

    [sender setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_FR"]];
    

提交回复
热议问题