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

Java SimpleDateFormat shifts Date by one year

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Java 1.7/1.8 Windows

      A DESCRIPTION OF THE PROBLEM :
      Please see the code below:

      import java.text.SimpleDateFormat;
      import java.text.DateFormat;
      class Date1{

                  public static void main(String[]args){
                              
                              DateFormat format = new SimpleDateFormat("dd-MMM-YYYY");
                              System.out.println("Date is "+ format.format(new java.util.Date("12/31/2020")));
                  }
      }
      The result is showing as Date is 31-DEC-2021 but actually the date should be 31-DEC-2020 because that is the requirement.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute above code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Date is 31-DEC-2020
      ACTUAL -
      Date is 31-DEC-2021

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: