Validating dates with day out of range

Viewed 34

When I try to parse date 2020-06-31 java successful parse it despite the fact that June have only 30 days (result is 30th of June).

My code

DateTimeFormatter DATE_FORMATTER =
            new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd")
                    .toFormatter();
LocalDate.from(DATE_FORMATTER.parse("2020-06-31"))
    .atStartOfDay()
    .atZone(ZoneId.of("Asia/Kuala_Lumpur"))
    .toInstant();

Is it possible to validate such dates?

PS: I use Java 1.8

0 Answers
Related