Change UIDatePicker Order?

2019-05-08 18:43发布

问题:

Seeing from this url, date picker is shown as month-date-year, can i change it to date-month-year?

回答1:

This is determined by the locale setting of the device it's running on, as per the Developer Page (look at the DatePicker mode sections).

The exact items shown and their order depend upon the locale set.

The property 'locale' can be used to explicitly specify a mode to use, but this is deprecated as of iOS 5. It's generally best to leave this setting alone, so that the date will display in the format most familiar to users for the region they have their phone set to.



回答2:

Set DatePicker local as "en_GB", you will get date-month-year order.

datePicker.datePickerMode = UIDatePickerMode.date

datePicker.locale = NSLocale(localeIdentifier: "en_GB") as Locale