简体   繁体   中英

Spanish java.time.format.DateTimeParseException on time String

I am attempting to use the Java 8 DateTimeFormatter class to parse a time string that is in Spanish. After several hours of searching, I cannot find any hints. The error being returned is:

java.time.format.DateTimeParseException: Text '905 PM AST MARTES 7 AGOSTO 2018' could not be parsed at index 4

This seem to be the start of the 'PM' element.

Here is the relevant code:

DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
builder.parseCaseInsensitive();
builder.appendPattern("hmm a z EEE d MMM yyyy");
DateTimeFormatter formatter = builder.toFormatter(new Locale("es", "PR"));

String spanishDate = "905 PM AST MARTES 7 AGOSTO 2018"
Instant issuanceInstant = Instant.from(formatter.parse(spanishDate));

I have tried formatting it differently, but this is a standard format used on meteorological messages that I need to parse. Any help would be greatly appreciated.

EEE and MMM are short form. You need to use 4 letters for full form:

hmm a z EEEE d MMMM yyyy

After reverting to Java 8, the bug has disappeared. Thanks for the help everyone! I'll file a report against it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM