I currently am migrating a piece of software from Java 11 to Java 17 and noticed that DateTimeFormatter has changed its behaviour when formatting time that contains the AM/PM marker. Earlier, that marker would have been localised (e.g. vorm. for AM in German) and now, it stays AM. This is not a locale-specific issue, because I already have tried this with other locales. The pattern that is being tried here is HH:mm:ss a, where a is the place holder of the marker. How can the previous behaviour be restored?
The DateTimeFormatter is being called using the ofPattern method as follows:
ofPattern("HH:mm:ss a", Locale.GERMANY).format(now).
The variable now is a LocalDateTime object.
I'm having the same problem. I found this: https://bugs.openjdk.org/browse/JDK-8297504
Basically it says in older unicode CLDR (v33) which java 11 is based on, German terms for AM/PM is nachm. and vorm.
But in CLDR v44 which java17 is based on they changed it to AM/PM.
This is the quote from the ticket(https://bugs.openjdk.org/browse/JDK-8297504):
It turned out that the change came from the upstream CLDR. In CLDR v33 which JDK 11 is based on, "pm" string is localized into German "nachm." (look for "·de·" in the right column): https://www.unicode.org/cldr/cldr-aux/charts/33/by_type/date_&_time.gregorian.html#72c7f54616968b69
whereas in CLDR v42 which the latest JDK is based on, "pm" string in German is "PM": https://unicode-org.github.io/cldr-staging/charts/latest/by_type/date_&_time.gregorian.html#72c7f54616968b69
So the current right way in German based on recent unicode is AM/PM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With