Close

Java Date Time - YearMonth.isValidDay() Examples

Java Date Time Java Java API 


Class:

java.time.YearMonth

java.lang.Objectjava.lang.Objectjava.time.YearMonthjava.time.YearMonthjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public boolean isValidDay(int dayOfMonth)

Checks if the day-of-month is valid for this year-month.


Examples


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);
}
}

Output

2010-02
false
2020-02
true




See Also