Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8297127

bug in DateTimeFormatter when using "MMM" (outputs Sept instead of Sep)

XMLWordPrintable

    • generic
    • generic

      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


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: