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

SimpleDateFormat.format(Date) now returns different String value for non-US

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10/JDK 11 (Have not checked JDK 11.0.1 yet)

      A DESCRIPTION OF THE PROBLEM :
      SimpleDateFormat.

      REGRESSION : Last worked in version 10

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Simple test code attached. To be specific, when construct SimpleDateFormat, not only provide the pattern, but also the Locale, then try to format a known date. The value returned by jdk 11 is different from previous jdks.
      For example, for Locale "CANADA", in jdk 11, it returns "05-Nov.-2018", while in 1.8.0_171, 9.0.4, 10.0.1, 11-ea-15, it has always returned "05-Nov-2018".. Note the in jdk 11, there is an extra dot "." right after the "Nov" month section.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      With explicit Locale and Pattern for SimpleDateFormat, it should return consistent values by jdk 11, namely
      ACTUAL -
      JDK 11 formats the date into a String with an extra dot (for Locale CANADA).
      Here are some results running attached test program:
      C:\Test>set JAVA_HOME=C:\1.8.0_171\Windows

      C:\Test>set PATH=%JAVA_HOME%\bin

      C:\Test>java -version
      java version "1.8.0_171"
      Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

      C:\Test>java TestSDF
      05-Nov-2018

      C:\Test>set JAVA_HOME=C:\9.0.4\Windows

      C:\Test>set PATH=%JAVA_HOME%\bin

      C:\Test>java -version
      java version "9.0.4"
      Java(TM) SE Runtime Environment (build 9.0.4+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

      C:\Test>java TestSDF
      05-Nov-2018

      C:\Test>set JAVA_HOME=C:\10.0.1\Windows

      C:\Test>set PATH=%JAVA_HOME%\bin

      C:\Test>java -version
      java version "10.0.1" 2018-04-17
      Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
      Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

      C:\Test>java TestSDF
      05-Nov-2018

      C:\Test>set JAVA_HOME=C:\11.ea.15\Windows

      C:\Test>set PATH=%JAVA_HOME%\bin

      C:\Test>java -version
      java version "11-ea" 2018-09-25
      Java(TM) SE Runtime Environment 18.9 (build 11-ea+15)
      Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+15, mixed mode)

      C:\Test>java TestSDF
      05-Nov-2018

      C:\Test>set JAVA_HOME=C:\11\Windows

      C:\Test>set PATH=%JAVA_HOME%\bin

      C:\Test>java -version
      java version "11" 2018-09-25
      Java(TM) SE Runtime Environment 18.9 (build 11+28)
      Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)

      C:\Test>java TestSDF
      05-Nov.-2018


      ---------- BEGIN SOURCE ----------
      import java.util.Locale;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      public class TestSDF {
          public static void main(String[] args) {
              Date aDate = new Date(1541431200000L);
              SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.CANADA);
              String dateToStr = sdf.format(aDate);
              System.out.println(dateToStr);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None.

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            psonal Pallavi Sonal (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: