Jeśli miesiąc ma wartość GŁĘBOKĄ lub małą, tzn. Nie zawiera tytułu, funkcja DateTimeFormatter nie może przeanalizować daty. Czy istnieje prosty sposób przekonwertowania daty na tytuł lub sposób, w jaki formater jest łagodniejszy?Jak obsługiwać duże lub małe litery w JSR 310?
for (String date : "15-JAN-12, 15-Jan-12, 15-jan-12, 15-01-12".split(", ")) {
try {
System.out.println(date + " => " + LocalDate.parse(date,
DateTimeFormatter.ofPattern("yy-MMM-dd")));
} catch (Exception e) {
System.out.println(date + " => " + e);
}
}
drukuje
15-JAN-12 => java.time.format.DateTimeParseException: Text '15-JAN-12' could not be parsed at index 3
15-Jan-12 => 2015-01-12
15-01-12 => java.time.format.DateTimeParseException: Text '15-01-12' could not be parsed at index 3
15-jan-12 => java.time.format.DateTimeParseException: Text '15-jan-12' could not be parsed at index 3
@hraldK Jeśli '.parseLenient()' nie zostanie ustawione, format "15-01-12" zakończy się niepowodzeniem. – SubOptimal