YearMonth atDay() method in Java
The atDay() method of YearMonth class in Java combines the current year-month with a day-of-month passed as parameter to it to create a LocalDate.
public LocalDate atDay(int dayOfMonth)
Parameter: This method accepts a single parameter dayOfMonth. It is the day-of-month to use. It can take values from 1 to 31.
Return Value: It returns a Local Date formed by the current year-month and a day of month passed as parameter to the function.
Exception: This method throws a DateTimeException, if the day of month passed in the parameter is not valid.
Below programs illustrate the atDay() method of YearMonth in Java:
Program 2: To illustrate Exception. The below program throws an exception as September is of 30 days and not 31 days.
java.time.DateTimeException: Invalid date 'SEPTEMBER 31'