I have to handle timestamps received from an external API in Java. An example of the datetime format could look like this:
"May 9, 2018 5:32:31 PM CEST"
After looking up information found in the documentation at DateTimeFormatter#Predefined Formatters I found that this format is not included as a predefined format. So I went on with defining my own DateTimeFormatter using DateTimeFormatter#Patterns for Formatting and Parsing and got the following error message:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'May 9, 2018 5:32:31 PM CEST' could not be parsed at index 0
So I went to "The Java Tutorials" and found that their example of parsing month names won't work in my programm...
From The Java Tutorials Parsing and Formatting:
String input = "Mar 23 1994";
try {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("MMM d yyyy");
LocalDate date = LocalDate.parse(input, formatter);
System.out.printf("%s%n", date);
}
catch (DateTimeParseException exc) {
System.out.printf("%s is not parsable!%n", input);
throw exc; // Rethrow the exception.
}
This throws the same error message, as parsing fails when reaching the name of the month... So my question is how to parse the datetime String from above using the java.time package.
The answer from this question is working correctly on my machine. (so the MMM
Pattern is working, but not when parsing from a String)
Thanks for any help!