A LocalDate represents a date consisting of a year, a month, and a day. You cannot do LocalDate unless you have these three fields. In this case, you parse the month and year, but there is no day. Therefore, you cannot parse it in LocalDate .
If the day does not matter, you can YearMonth it in YearMonth :
YearMonth is an immutable time object that represents a combination of year and month.
public static void main(String[] args) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMyy").withZone(ZoneId.of("UTC")); YearMonth yearMonth = YearMonth.parse("0216", formatter); System.out.println(yearMonth);
Then you can convert this YearMonth to LocalDate by setting it to the first day of the month, for example:
LocalDate localDate = yearMonth.atDay(1);
source share