[quote='789352022, BabyJ, /thread/756212?answerId=789352022#789352022, /profile/BabyJ']
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
[/quote]
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"
Post
Replies
Boosts
Views
Activity
[quote='789178022, BabyJ, /thread/756212?answerId=789178022#789178022, /profile/BabyJ']
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.
[/quote]
In UIKit above property isn't available
[quote='238252022, DTS Engineer, /thread/80512?answerId=238252022#238252022']
Formats containing specific fields, by passing those fields to DateFormatter.dateFormat(fromTemplate:options:locale:) and then applying the resulting string to the dateFormat property of your date formatter
[/quote]
above method works But i set "dd-mm-yy" or "dd.mm.yy" in template but it return "dd/mm/yy" format String
"timeFormat.isEqual("HH:mm") ? Locale(identifier: "en_GB") : Locale(identifier: "en_US")". // "en_GB" for 24 && "en_US" for 12 hour time formats
I used above code its work properly but when i set device region is unitedState always show 24 hour time format in DateTimePicker , this issue occurred above iOS 17 versions, anyone face this issue? please provide a propper solution