Open LetsSamba opened 2 weeks ago
This seems locale dependent and en_GB
provides different output between JDK versions. Likely due to changes in Locale providers. Specifying -Djava.locale.providers=compat
results in upper case formatting in JDK 21.
If you are relying on the upper case spelling there is a SimpleDateFormatter
constructor taking a DateFormatSymbols
instance, which you can configure to use upper-case AM/PM indicators using setAmPmStrings()
which is more reliable.
import java.text.SimpleDateFormat;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
public class AmPmDemo {
public static void main(String[] args) {
System.out.println(Locale.getDefault());
DateFormatSymbols dfs = new DateFormatSymbols();
dfs.setAmPmStrings(new String[] { "AM", "PM" });
SimpleDateFormat sdf = new SimpleDateFormat("a hh:mm", dfs);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Calendar calendar = Calendar.getInstance();
System.out.println(sdf.format(calendar.getTime()));
}
}
@jerboaa Thanks for your workaround. My expectation was that upgrading from Java 8 to Java 21 should be a painless experience, as long as I wasn't trying to use something that has been deprecated. In my case, some JUnit tests had failed and I had to spend time investigating.
Please provide a brief summary of the bug
Adoptium Java formats the AM/PM indicator to lower case but Java 8 formats it to upper case.
Did you test with the latest update version?
Please provide steps to reproduce where possible
Expected Results
Java 8 outputs the following:
en_GB PM 01:50
Therefore that is what I expected from Adoptium Java.
Actual Results
I got this:
en_GB pm 01:50
What Java Version are you using?
openjdk 21.0.3 2024-04-16 LTS OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing)
What is your operating system and platform?
Windows 11 22H2 on x86-64
How did you install Java?
Using the MSI.
Did it work before?
Did you test with other Java versions?
Relevant log output
No response