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

SimpleDateFormat increments year by 1 for all the dates in last week of theyear

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The issue occurs when the last week of the year has Jan 01st falling on any day from Monday to Saturday, then all the previous days of that week has the year incremented by 1.
      For instance if Jan 01st(Ex: 01/01/2025) falls on Wednesday, then the dates from Sunday till Tuesday(29/12/2024, 30/12/2024, 31/12/2024) in that week has a bug with respect to year. The output after using SimpleDateFormat class gives(29/12/2025, 30/12/2025 and 31/12/2025 respectively)



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      If the date "25/12/2021" is formatted using SimpleDateFormat, the output is displayed as "25/12/2021"
      But if the date "26/12/2021" is formatted then the output is "26/12/2022" and all the dates from 26th Dec to 31st Dec , the formatted date has year 2022.
      Likewise, if the date "31/12/2023" is formatted then the output is "31/12/2024"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Irrespective of 01st Jan falling on any day of the week, the formatted date should be displayed correctly without any increment
      Example: If the date is 27/12/2021 then the formatted date should be 27/12/2021
      ACTUAL -
      If the date is 27/12/2021, the formatted date is 27/12/2022

      ---------- BEGIN SOURCE ----------
      SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/YYY");
      Date date = new Date();
      dateFormat.format(date);

      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: