FULL PRODUCT VERSION :
this is probably irrelevant
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
3.19.0-61-generic #69~14.04.1-Ubuntu SMP Thu Jun 9 09:09:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
its really just appears to be a documentation bug
A DESCRIPTION OF THE PROBLEM :
your line:
M/L month-of-year number/text 7; 07; Jul; July; J
should probably be either:
M/L month-of-year text/number 7; 07; Jul; July; J
or
L/M month-of-year number/text 7; 07; Jul; July; J
the order of letters in the first column should reflect the order of values in the third column
REGRESSION. Last worked in version 8u73
ADDITIONAL REGRESSION INFORMATION:
it really just appears to be a documentation bug
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;
class DTF {
public static void main(String[] args) {
String ds = "Fri Apr 01 00:13:53 EDT 2016";
String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
System.err.println(dtfmt);
DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);
String text = date.format(fmtr);
System.err.println(text);
System.err.println(date.toString());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
since the string contains 'Apr', I expected that I should have used 'LLL' instead of 'MMM' to parse the
string.
In this case, I would expect a date parse exception such as this:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Fri Apr 01 00:13:53 EDT 2016' could not be parsed at index 4
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at DTF.main(DTF.java:15)
ACTUAL -
EEE MMM dd HH:mm:ss z yyyy
Fri Apr 01 00:13:53 EDT 2016
2016-04-01T00:13:53-04:00[America/New_York]
ERROR MESSAGES/STACK TRACES THAT OCCUR :
I got no error message with the format string "EEE MMM dd HH:mm:ss z yyyy"
with the format string "EEE LLL dd HH:mm:ss z yyyy", I get:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Fri Apr 01 00:13:53 EDT 2016' could not be parsed at index 4
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at DTF.main(DTF.java:15)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;
class DTF {
public static void main(String[] args) {
String ds = "Fri Apr 01 00:13:53 EDT 2016";
String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
System.err.println(dtfmt);
DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);
String text = date.format(fmtr);
System.err.println(text);
System.err.println(date.toString());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;
class DTF {
public static void main(String[] args) {
String ds = "Fri Apr 01 00:13:53 EDT 2016";
String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
System.err.println(dtfmt);
DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);
String text = date.format(fmtr);
System.err.println(text);
System.err.println(date.toString());
}
}
this is probably irrelevant
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
3.19.0-61-generic #69~14.04.1-Ubuntu SMP Thu Jun 9 09:09:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
its really just appears to be a documentation bug
A DESCRIPTION OF THE PROBLEM :
your line:
M/L month-of-year number/text 7; 07; Jul; July; J
should probably be either:
M/L month-of-year text/number 7; 07; Jul; July; J
or
L/M month-of-year number/text 7; 07; Jul; July; J
the order of letters in the first column should reflect the order of values in the third column
REGRESSION. Last worked in version 8u73
ADDITIONAL REGRESSION INFORMATION:
it really just appears to be a documentation bug
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;
class DTF {
public static void main(String[] args) {
String ds = "Fri Apr 01 00:13:53 EDT 2016";
String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
System.err.println(dtfmt);
DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);
String text = date.format(fmtr);
System.err.println(text);
System.err.println(date.toString());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
since the string contains 'Apr', I expected that I should have used 'LLL' instead of 'MMM' to parse the
string.
In this case, I would expect a date parse exception such as this:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Fri Apr 01 00:13:53 EDT 2016' could not be parsed at index 4
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at DTF.main(DTF.java:15)
ACTUAL -
EEE MMM dd HH:mm:ss z yyyy
Fri Apr 01 00:13:53 EDT 2016
2016-04-01T00:13:53-04:00[America/New_York]
ERROR MESSAGES/STACK TRACES THAT OCCUR :
I got no error message with the format string "EEE MMM dd HH:mm:ss z yyyy"
with the format string "EEE LLL dd HH:mm:ss z yyyy", I get:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Fri Apr 01 00:13:53 EDT 2016' could not be parsed at index 4
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at DTF.main(DTF.java:15)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;
class DTF {
public static void main(String[] args) {
String ds = "Fri Apr 01 00:13:53 EDT 2016";
String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
System.err.println(dtfmt);
DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);
String text = date.format(fmtr);
System.err.println(text);
System.err.println(date.toString());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;
class DTF {
public static void main(String[] args) {
String ds = "Fri Apr 01 00:13:53 EDT 2016";
String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
System.err.println(dtfmt);
DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);
String text = date.format(fmtr);
System.err.println(text);
System.err.println(date.toString());
}
}
- relates to
-
JDK-8114833 java.time.format.DateTimeFormatter does not work as documented
-
- Closed
-