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

SimpleDateFormat outputs AM and PM as lower case

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Hardware - Dell Optiplex 790; OS Windows 7 Professional SP1; JDK openjdk-11+28, java -version=openjdk version "11" 2018-9-25 OpenJDK Runtime Environment 18.9 (build 11+28)

      A DESCRIPTION OF THE PROBLEM :
      SimpleDateFormat used to output AM and PM as upper case with the 'a' format option. In JDK11 it is lower case

      REGRESSION : Last worked in version 8u181

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Format a time using the 'a' option to give AM or PM using SimpleDateFormat. See below for a simple test - works Ok with Java 8 but not 11.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting time to be formatted AM and PM in line with previous releases
      ACTUAL -
      Time was formatted am and pm

      ---------- BEGIN SOURCE ----------

      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      public class SDFTester
      {

        public final static String FORMAT_OUT="hh:mma";
        public final static String FORMAT_IN="yyyyMMddHHmmss";
        public static void main(String[] args)
        {
         testFormat("20181008110300");
         testFormat("20181008170300");
         
        }
      private static void testFormat(String aDate)
      {
          try
          {
            SimpleDateFormat sdf1=new SimpleDateFormat(FORMAT_IN);
            SimpleDateFormat sdf2=new SimpleDateFormat(FORMAT_OUT);
            Date date =sdf1.parse(aDate);
            String output=sdf2.format(date);
           System.out.println(output);
           if (output.substring(6, 7).equals("M"))
           {
             System.out.println("Formatting is OK");
           }
           else
           {
             System.out.println("Formatting is not OK");
           }
          }
          catch (ParseException pe)
          {
            
          }
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Could use toUpperCase but this needs code changes.

      FREQUENCY : always


        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: