The isValidDay() method of YearMonth class in Java is used to check if this YearMonth object and a month-day represented by an integer provided as a parameter to the method together can form a valid date or not.
Syntax:
public boolean isValidDay(int monthDay)
Parameter: This method accepts a single parameter monthDay which represents a month-day which is need to be examined with this YearMonth object.
Return Value: It returns a boolean True value if this YearMonth object and the given month-day represented as an integer together can form a valid date otherwise it returns False.
Below programs illustrate the YearMonth.isValidDay() method in Java:
Program 1:
// Program to illustrate the isValidDay() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Create YearMonth object YearMonth yearMonth = YearMonth.of(2016, 2); // Check if the day passed is valid System.out.println(yearMonth.isValidDay(24)); } } |
true
Program 2: In the below program, Year is mentioned as 1990 which is not a leap year but month-day represents a leap year. So, they together can not form a valid date so the method will return false.
// Program to illustrate the isValidDay() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Create YearMonth object YearMonth yearMonth = YearMonth.of(1990, 2); // Check if the day passed is valid System.out.println(yearMonth.isValidDay(29)); } } |
false
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#isValidDay-java.time.MonthDay-
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- YearMonth now() method in Java with Examples
- YearMonth of(int, int) method in Java with Examples
- YearMonth until() Method in Java with Examples
- YearMonth get() method in Java with Examples
- YearMonth with() Method in Java with Examples
- YearMonth now(clock) method in Java with Examples
- YearMonth isLeapYear() method in Java with Examples
- YearMonth minusMonths() method in Java with Examples
- YearMonth withYear() method in Java with Examples
- YearMonth withMonth() method in Java with Examples
- YearMonth query() Method in Java with Examples
- YearMonth of(int, Month) method in Java with Examples
- YearMonth plus(TemporalAmount) method in Java with Examples
- YearMonth lengthOfYear() method in Java with Examples
- YearMonth plusYears() method in Java with Examples
- YearMonth plusMonths() method in Java with Examples
- YearMonth getLong() method in Java with Examples
- YearMonth isAfter() method in Java with Examples
- YearMonth isBefore() method in Java with Examples
- YearMonth range() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

