Matt Davis
Matt Davis

Reputation: 31

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.

Upvotes: 3

Views: 210

Answers (2)

Matt Davis
Matt Davis

Reputation: 31

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

Upvotes: 0

shmosel
shmosel

Reputation: 50716

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

hmm a z EEEE d MMMM yyyy

Upvotes: 3

Related Questions