java.time.YearMonth.isValidDay() Method Example



Description

The java.time.YearMonth.isValidDay(int dayOfMonth) method checks if the day-of-month is valid for this year-month.

Declaration

Following is the declaration for java.time.YearMonth.isValidDay(int dayOfMonth) method.

public boolean isValidDay(int dayOfMonth)

Parameters

dayOfMonth − the day-of-month to validate, from 1 to 31, invalid value returns false.

Return Value

true if the day is valid for this year-month.

Example

The following example shows the usage of java.time.YearMonth.isValidDay(int dayOfMonth) method.

package com.tutorialspoint;

import java.time.YearMonth;

public class YearMonthDemo {
   public static void main(String[] args) {
      
      YearMonth date = YearMonth.of(2020,11);
      System.out.println(date.isValidDay(30));  
   }
}

Let us compile and run the above program, this will produce the following result −

true
Advertisements