Java Date Time Java Java API
java.time.YearMonth
public boolean isValidDay(int dayOfMonth)
Checks if the day-of-month is valid for this year-month.
package com.logicbig.example.yearmonth;import java.time.YearMonth;public class IsValidDayExample { public static void main(String... args) { YearMonth y = YearMonth.of(2010, 2); System.out.println(y); boolean b = y.isValidDay(29); System.out.println(b); //leap year YearMonth y2 = YearMonth.of(2020, 2); System.out.println(y2); boolean b2 = y2.isValidDay(29); System.out.println(b2); }}
2010-02false2020-02true