Does LocalDate.parse silently correct day number?
问题 String s = "2020 Jun 31"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MMM dd"); LocalDate date = LocalDate.parse(s, formatter); System.out.println(date); Output: 2020-06-30 Why does 31 turn into 30 without any warnings or exceptions? 回答1: DateTimeFormatter has a ResolverStyle that affects how strict or lenient the parser should be with invalid date and time values. To get an exception in this case you need to set the resolver style to STRICT. You also need to use u (year)