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

DateTimeFormatter fail to parse time string when seconds and milliseconds are 0s

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 10.0.1
    • core-libs
    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      As already mention in this Question in

      StackOveflow https://stackoverflow.com/questions/49967139/java-datetimeformatter-fail-to-parse-time-string-when-seconds-and-milliseconds

      This piece of code should return for this "20180301091600000" with this "yyyyMMddHHmmssSSS" patter a result : "2018-03-01T09:16:00.000" note the last part "00.000" for seconds and milliseconds.
      Instead it return "2018-03-01T09:16".


      REGRESSION : Last worked in version 10.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      DateTimeFormatter dtformatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
      var result = LocalDateTime.parse("20180301091600000", dtformatter);
      System.out.println(result);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      2018-03-01T09:16:00.000
      ACTUAL -
      2018-03-01T09:16

      CUSTOMER SUBMITTED WORKAROUND :
      A temporary solution is like I mentioned here https://stackoverflow.com/a/49967274/5558072

      We need to parse the date with another formatter like this :

      var result = LocalDateTime.parse("20180301091600001", dtformatter)
                                          .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss:SSS"));

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: