iOS16 Date format does not update when setLocalizedDateFormatFromTemplate is used

Hi,

With iOS16, we have a new setting named Date Format in Language&Region menu. When I use setLocalizedDateFormatFromTemplate to format my date, changing Date Format setting does not update the format of my date.

This is my code to format my date:

let formatter = DateFormatter()
formatter.setLocalizedDateFormatFromTemplate("ddMMyyyy")
formatter.calendar = .autoupdatingCurrent
formatter.locale = .autoupdatingCurrent
formatter.timeZone = .autoupdatingCurrent
let myText = formatter.string(from: Date())

I provided this template as an example. I have other templates like "dMMMMyyyy" or "dMMMM" and none of them gets updated when date format setting is changed.

Hi, thanks for the report! It seems similar in some aspects to your feedback FB11909995 from this other thread. I have forwarded your feedback.

Try setting the template as the last step rather than the first step.

Do you mean to try like this? If so, it does not work either.

let formatter = DateFormatter()
formatter.calendar = .autoupdatingCurrent
formatter.locale = .autoupdatingCurrent
formatter.timeZone = .autoupdatingCurrent
formatter.setLocalizedDateFormatFromTemplate("dMMyyyy")
let myText = formatter.string(from: Date())

By the way, for dMMyyyy and dMMMMyyyy, I can use the already pre-defined styles like .short and .long and formatting works fine with those styles. However, for dMMMM template, there is not any pre-defined style.

@hasancanakgunduz52 I am also facing the same issue with my business requirement. Did you found the solution for it?

iOS16 Date format does not update when setLocalizedDateFormatFromTemplate is used
 
 
Q