Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Datepicker in am-pm format

I have the following date picker:

DatePicker("Time", selection: $wakeUp, displayedComponents: .hourAndMinute)

That would be using the 24h format by default like this:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I set it to am/pm format like this:

enter image description here

I tried the following:

DatePicker("Time", selection: $wakeUp, displayedComponents: [.hourAndMinute, .dateFormat = "hh:mm a"])

but it’s not working. How can I have the time picker (only the time, not date) in am/pm format?

>Solution :

The picker will respect the locale. So, if you what to overrule the system settings you can set the desired locale on the picker like this:

picker.locale = Locale.init(identifier: "en")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading