FULL PRODUCT VERSION :
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.8.5 (Mountain Lion).
A DESCRIPTION OF THE PROBLEM :
In the new java.time package, the documentation for the DateTimeFormatter class describes fraction-of-second as just another part of a date-time like any other part. Yet it treats fraction-of-second as special when parsing a string: A PERIOD character is required. Without a "." in the input string being parsed, and in the format pattern, an exception is thrown. The documentation says nothing about a period being required.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This code works:
String input = "20111203123456";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmss");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );
Rendering:
2011-12-03T12:34:56
But when adding the uppercase "S" for fraction of second, an exception is thrown. This code:
String input = "2011120312345655";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSS");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );
throws this exception:
java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected this string:
2011-12-03T12:34:56.55
ACTUAL -
Throws this exception:
java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
String input = "2011120312345655";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSS");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None. A string without punctuation for the fraction-of-second cannot be parsed.
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.8.5 (Mountain Lion).
A DESCRIPTION OF THE PROBLEM :
In the new java.time package, the documentation for the DateTimeFormatter class describes fraction-of-second as just another part of a date-time like any other part. Yet it treats fraction-of-second as special when parsing a string: A PERIOD character is required. Without a "." in the input string being parsed, and in the format pattern, an exception is thrown. The documentation says nothing about a period being required.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This code works:
String input = "20111203123456";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmss");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );
Rendering:
2011-12-03T12:34:56
But when adding the uppercase "S" for fraction of second, an exception is thrown. This code:
String input = "2011120312345655";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSS");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );
throws this exception:
java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected this string:
2011-12-03T12:34:56.55
ACTUAL -
Throws this exception:
java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
String input = "2011120312345655";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSS");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None. A string without punctuation for the fraction-of-second cannot be parsed.
- duplicates
-
JDK-8031085 DateTimeFormatter won't parse dates with custom format "yyyyMMddHHmmssSSS"
- Resolved