Year isValidMonthDay() method in Java
The isValidMonthDay() method of Year class in Java is used to check if this Year object and a month-day represented by a MonthDay provided as a parameter to the method together can form a valid date or not.
Syntax:
public boolean isValidMonthDay(MonthDay monthDay)
Parameter: This method accepts a single parameter monthDay which represents a month-day which is need to be examined with this Year object.
Return Value: It returns a boolean True value if this Year object and the given month-day represented by a MonthDay together can form a valid date otherwise it returns False.
Below programs illustrate the isValidMonthDay() method of Year in Java:
Program 1:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 2016 );
MonthDay monthDay = MonthDay.of( 9 , 15 );
System.out.println(thisYear.isValidMonthDay(monthDay));
}
}
|
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.
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 1990 );
MonthDay monthDay = MonthDay.of( 2 , 29 );
System.out.println(thisYear.isValidMonthDay(monthDay));
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#isValidMonthDay-java.time.MonthDay-
Last Updated :
27 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...