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

SimpleDateFormat parses incorrectly. Parse "2020 Nov 13", format "2020 Dec 29".

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      java.version=14.0.1
      os.version=10.0
      java.runtime.name=Java(TM) SE Runtime Environment
      java.vm.name=Java HotSpot(TM) 64-Bit Server VM
      java.version.date=2020-04-14
      jdk.debug=release
      ava.vm.specification.version=null
      os.name=Windows 10
      java.specification.version=14
      sun.cpu.isalist=amd64

      A DESCRIPTION OF THE PROBLEM :
      Parsing "2020 Nov 13" with SimpleDateFormat("YYYY MMM dd") then formatting returned Date with same SimpleDateFormat("YYYY MMM dd") gives "2020 Dec 29". Date.toString() gives "Sun Dec 29 00:00:00 CST 2019".

      REGRESSION : Last worked in version 14.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and execute Demo program.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      inputString=2020 Nov 13
      date=Sun Nov 13 00:00:00 CST 2020
      format=2020 Nov 13


      ACTUAL -
      inputString=2020 Nov 13
      date=Sun Dec 29 00:00:00 CST 2019
      format=2020 Dec 29

      java.version=14.0.1
      os.version=10.0
      java.runtime.name=Java(TM) SE Runtime Environment
      java.vm.name=Java HotSpot(TM) 64-Bit Server VM
      java.version.date=2020-04-14
      jdk.debug=release
      ava.vm.specification.version=null
      os.name=Windows 10
      java.specification.version=14
      sun.cpu.isalist=amd64

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      import java.text.*;
      class TestDateBug
      {
          public static void main(String[] args) throws ParseException
          {
              SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY MMM dd");

              String inputString = "2020 Nov 13";
              Date date = dateFormat.parse(inputString);

              System.out.println("inputString="+inputString);
              System.out.println("date="+date);
              System.out.println("format="+dateFormat.format(date));
              System.out.println();

              System.out.println("java.version="+System.getProperties().getProperty("java.version"));
              System.out.println("os.version="+System.getProperties().getProperty("os.version"));
              System.out.println("java.runtime.name="+System.getProperties().getProperty("java.runtime.name"));
              System.out.println("java.vm.name="+System.getProperties().getProperty("java.vm.name"));
              System.out.println("java.version.date="+System.getProperties().getProperty("java.version.date"));
              System.out.println("jdk.debug="+System.getProperties().getProperty("jdk.debug"));
              System.out.println("ava.vm.specification.version="+System.getProperties().getProperty("ava.vm.specification.version"));
              System.out.println("os.name="+System.getProperties().getProperty("os.name"));
              System.out.println("java.specification.version="+System.getProperties().getProperty("java.specification.version"));
              System.out.println("sun.cpu.isalist="+System.getProperties().getProperty("sun.cpu.isalist"));
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None found

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            sswsharm swati sharma
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: