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

Parse exception: Unparseable date due to DateFormat.getDateTimeInstance

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 11 Enterprise 23H2 22631.5189 x64

      Java 17.0.13, Oracle openjdk 21.0.7 , Oracle openjdk 24.0.1

      A DESCRIPTION OF THE PROBLEM :
      while running

      import java.text.*;
      import java.util.*;
      public class Main {
          public static void main(String args[]) throws ParseException {
              DateFormat date = DateFormat.getDateTimeInstance(2, 2, Locale.US);
              String s = "Apr 23, 2025, 8:00:59 PM";

              // Print the actual pattern being used
              if (date instanceof SimpleDateFormat) {
                  System.out.println("Format pattern: " + ((SimpleDateFormat)date).toPattern());
              }

              try {
                  Date parsedDate = date.parse(s);
                  System.out.println("Parsed date: " + parsedDate);
              } catch (ParseException e) {
                  System.out.println("Parse exception: " + e.getMessage());
              }
          }
      }



      Result for Oracle openjdk 21.0.7 :
      Format pattern: MMM d, y, h:mm:ss a
      Parse exception: Unparseable date: "Apr 23, 2025, 8:00:59 PM"

      but when running with Java 17.0.13 or Oracle 24.0.1
      we are able to parse date using same code

      Result for java 17.0.13 :
      Format pattern: MMM d, y, h:mm:ss a
      Parsed date: Wed Apr 23 20:00:59 IST 2025

      Result for Oracle openjdk 24.0.1 :
      Format pattern: MMM d, y, h:mm:ss a
      Parsed date: Wed Apr 23 20:00:59 IST 2025

      REGRESSION : Last worked in version 17

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run main function of Main class code given in description in with Oracle openjdk 21.0.7 getting Parse exception: Unparseable date: "Apr 23, 2025, 8:00:59 PM"

      and run same code with Oracle openjdk 24.0.1 or Java 17.0.13
      able to parse date


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Format pattern: MMM d, y, h:mm:ss a
      Parsed date: Wed Apr 23 20:00:59 IST 2025
      ACTUAL -
      Format pattern: MMM d, y, h:mm:ss a
      Parse exception: Unparseable date: "Apr 23, 2025, 8:00:59 PM"

      ---------- BEGIN SOURCE ----------
      import java.text.*;
      import java.util.*;
      public class Main {
          public static void main(String args[]) throws ParseException {
              DateFormat date = DateFormat.getDateTimeInstance(2, 2, Locale.US);
              String s = "Apr 23, 2025, 8:00:59 PM";

              // Print the actual pattern being used
              if (date instanceof SimpleDateFormat) {
                  System.out.println("Format pattern: " + ((SimpleDateFormat)date).toPattern());
              }

              try {
                  Date parsedDate = date.parse(s);
                  System.out.println("Parsed date: " + parsedDate);
              } catch (ParseException e) {
                  System.out.println("Parse exception: " + e.getMessage());
              }
          }
      }


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

            cgaffney Cody Gaffney
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: