Change UIDatePicker from 12-Hour Beat to 24 Hours and Back

I'm sorry that my first question is a bit simple here - I spent a day reading the NSLocale and NSCalendar class descriptions, but I could not figure out if this was possible.

I have a UIDatePicker in UIDatePickerModeDateAndTime mode. It currently displays the date and time according to the user locale, which is the default behavior.

I would like to provide the ability to display UIDatePicker in 12 hour or 24 hour time format. Finding out which time format the user is currently using is not a problem, but I don’t understand how to change only the UIDatePicker time format without throwing away the user's locale settings (since the collector also displays localized days, week and months). UIDatePicker supports customizing your locale and customizing your calendar.

So, one question is whether I need to do something using NSLocale or NSCalendar, and the second question is if someone can recommend a way to isolate the time format without throwing away the rest of the user's language standard settings.

Thanks for any suggestions.

+3
3

, , , , , UIDatePicker , " t . .

+1

, , Cocoa NSDateFormatter NSDatePicker ( NSControl) setFormatter. , iPhone (UIControl) . Apple , , , / /.

+1

, AM/PM, AM PM 12- . 24- NSCalendar. :

var hra = 1//ENTER INITIAL HOUR (HH)

var dna = "PM"//ENTER "AM" OR "PM"

if hra <= 12 && dna == "PM"{

     hra = hra + 12
}

The hra variable now takes the value of the 24-hour format.

0
source

Source: https://habr.com/ru/post/1710062/


All Articles