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

There is difference in years when format date using DateTimeFormatter

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Local date is 31/12/2021 but when we format date using DateTimeFormatter we get date in which year value is changed to next year
      for eg. current date is 31/12/2021 but after formatting we get 31/12/2022

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See the source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      31/12/2021
      ACTUAL -
      31/12/2022

      ---------- BEGIN SOURCE ----------
      import java.time.LocalDate;
      import java.time.format.DateTimeFormatter;

      public class Main {

          public static void main(String[] args) {
              DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MMM dd, YYYY");
              LocalDate localdate = LocalDate.of(2021, 12, 31);
              System.out.println(localdate);
              System.out.println(dtf.format(localdate));
          }
      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: