How to set timeFormat of DatePicker in swift

DatePicker always get timeFormat from device setting, but i need to show time in datePicker based on My app setting not device setting. any solution for this problem

I tried to set locale "us_POSIX" locale for 12 hour and "us_GB" for 24 hour format this way is work in gregorian calendar , but in japanese calendar not showing year properly like (picker showing " 6 " instead of " Reiwa 6 " )

How are you setting your locale?

If you aren't already, you can set it through the environment, like this:

DatePicker(...)
    .environment(\.locale, myCustomLocale)

You can customise a Locale object with the values you want for specified properties, such as the region or calendar.

How are you setting your locale?

If you aren't already, you can set it through the environment, like this:

DatePicker(...)
    .environment(\.locale, myCustomLocale)

You can customise a object with the values you want for specified properties, such as the region or calendar.

In UIKit above property isn't available

So you're not using SwiftUI. You should probably place this post in the UIKit topic instead so it's less confusing.


In UIKit above property isn't available

I believe UIDatePicker has a locale property that you can assign a custom locale to. It will do the same as the SwiftUI solution.

If this doesn't work, or you have already tried it, then you need to provide more context and the code you are using so we can understand what is going on.

So you're not using SwiftUI. You should probably place this post in the UIKit topic instead so it's less confusing.

In UIKit above property isn't available

I believe UIDatePicker has a locale property that you can assign a custom locale to. It will do the same as the SwiftUI solution.

If this doesn't work, or you have already tried it, then you need to provide more context and the code you are using so we can understand what is going on.

0  comments

yes, but if i set custom locale "us_POSIX" locale for 12 hour and "us_GB" for 24 hour format. working fine in device use gregorian calendar else datePicker year not showing properly in month & year section like when i use japanese calendar year shows "6" instead of "Reiwa 6"

How to set timeFormat of DatePicker in swift
 
 
Q