Home > database >  Datepicker in am-pm format
Datepicker in am-pm format

Time:07-02

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

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?

CodePudding user response:

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")
  • Related