2011-01-27 119 views
4

我的UIDatePicker設置爲UIDatePickerModeTime,但在它說的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 ].的蘋果文檔中。我如何添加上午/下午,因爲在我的設備上,這些不是選項,而是使用24小時制?添加上午/下午到datepicker?

回答

19

這取決於用戶的設置。如果你去設置 - >一般 - >日期&時間。有一個「24小時」時間開關,並根據用戶在您的選擇器上有AM/PM指示器。

3

不幸的是UIDatePicker沒有這個選項;它始終尊重12小時或24小時的設備選項。

如果必須有你可能有一個自定義UIPickerView去代替,並手動建立一個NSDate其組件的AM/PM構件。

+1

try datepicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@「en_US_POSIX」]; – 2015-05-05 07:03:06