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

DateFormat output changed between versions.

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Mac or Linux, Java 8 and Java 11

      A DESCRIPTION OF THE PROBLEM :
      When using DateFormat.format the timezone is output differently depending on Java version

      REGRESSION : Last worked in version 11.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the supplied class with Java 8 and Java 11


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The output is the same, regardless of versions.
      ACTUAL -
      The output of Java 8 is "09/08/2001 at 8:46:39 PM CDT"
      The output of Java 11 is "09/08/2001 at 8:46:39 PM Central Daylight Time"

      ---------- BEGIN SOURCE ----------
      import org.junit.Test;

      import java.text.DateFormat;
      import java.text.SimpleDateFormat;
      import java.util.Date;
      import java.util.GregorianCalendar;
      import java.util.TimeZone;

      public class TestStuff {
        @Test
        public void testJustTimeStuff() {
          String day = "";
          String time = "";
          TimeZone tz = TimeZone.getTimeZone("US/Central");
          SimpleDateFormat smf = new SimpleDateFormat("MM/dd/yyyy");
          smf.setTimeZone(tz);
          GregorianCalendar gc = new GregorianCalendar();
          Date d = new Date(999999999999L);
          gc.setTime(d);
          day = smf.format(gc.getTime());
          DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.FULL);
          timeFormat.setTimeZone(tz);
          time = timeFormat.format(gc.getTime());
          System.out.println(day + " at " + time);
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Haven't implemented a workaround but I imagine a Map<String,String> with the desired vs new versions could be used

      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: