I get a query parameter with an unknown time (date, time or timestamp in ISO format) and I want to analyze it for java.time.temporal.TemporalAccessor:
LocalDatewhen a string represents a date of type "2018-02-28"- or
LocalDateTimewhen the string represents a timestamp of type"2018-02-28T11:20:00"
The following attempt results in DateTimeParseException:
TemporalAccessor dt = DateTimeFormatter.ISO_DATE_TIME.parseBest(str, LocalDateTime::from, LocalDate::from);
The decision about the length of the string or the appearance of the “T” that is being used DateTimeFormatterseems a bit hacked to me. Just like trying one format after another.
The best decision?
Titus source
share