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

Failed to format a datetime using a specific format

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u51, 9
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      Can parse a LocalDateTime using the following pattern: "yyyyMMddHHmmssSSS"
      However this pattern works "yyyyMMddHHmmss.SSS"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try parsing a string in the "yyyyMMddHHmmssSSS" format using:
      LocalDateTime.parse("20150910121314987", DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      no exception thrown and date successfully parsed
      ACTUAL -
      DateTimeParseException is thrown
      Exception in thread "main" java.time.format.DateTimeParseException: Text '20150921165941914' could not be parsed at index 0
      at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
      at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
      at java.time.LocalDateTime.parse(LocalDateTime.java:492)
      at TestLocalDataTimeFormat.main(TestLocalDataTimeFormat.java:11)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.time.format.DateTimeParseException: Text '20150921165941914' could not be parsed at index 0
      at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
      at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
      at java.time.LocalDateTime.parse(LocalDateTime.java:492)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.time.format.DateTimeFormatter;
      import java.time.LocalDateTime;

      public class TestLocalDataTimeFormat {

        public static void main(String[] args) {
            LocalDateTime now = LocalDateTime.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
            String date = formatter.format(now);
            System.out.println("date to parse: "+now);
            LocalDateTime.parse(date, formatter); // throws an exception
        }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use the following format (mind the '.'): "yyyyMMddHHmmss.SSS"

      LocalDateTime.parse("20150910121314987", DateTimeFormatter.ofPattern("yyyyMMddHHmmss.SSS"))

      or alternatively use jodatime library

        Issue Links

          Activity

          Hide
          psonal Pallavi Sonal added a comment -
          This does not looks like a bug , as per the ISO-8601 calendar system its working with the format yyyyMMddHHmmss.SSS.
          However, it may be considered as an enhancement request to support the format with no '.' before the milliseconds.

          Moving to dev-team for evaluation.
          Show
          psonal Pallavi Sonal added a comment - This does not looks like a bug , as per the ISO-8601 calendar system its working with the format yyyyMMddHHmmss.SSS. However, it may be considered as an enhancement request to support the format with no '.' before the milliseconds. Moving to dev-team for evaluation.
          Hide
          scolebourne Stephen Colebourne added a comment -
          This is a duplicate of JDK-8031085
          Show
          scolebourne Stephen Colebourne added a comment - This is a duplicate of JDK-8031085

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: