JDK-8297127 : bug in DateTimeFormatter when using "MMM" (outputs Sept instead of Sep)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 19
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2022-11-16
  • Updated: 2022-11-16
  • Resolved: 2022-11-16
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
MacOS Ventura 13.0
64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
DateTimeFormatter.ofPattern("MMM") outputs the incorrect length for the month of September. expected is 3 characters in length, but java 19 outputs 4 characters (Sept). All other months are correctly 3 characters in length.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
output the month for September using DateTimeFormatter.ofPattern("MMM")
expected "Sep", but result is "Sept"
all other months are correct except September

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
ACTUAL -
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sept
Oct
Nov
Dec

---------- BEGIN SOURCE ----------
public class Test {
    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("MMM");
        // outputs correctly except for September (Sept instead of Sep)
        for (int i = 1; i <= 12; i++)
            System.out.println(localDate.withMonth(i).format(monthFormatter));

	}
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
This issue looks like a duplicate of JDK-8293917. By changing DateTimeFormatter.ofPattern("MMM") to DateTimeFormatter.ofPattern("MMM",Locale.US), the output is Sep.
16-11-2022