The atMonth(int) method of Year class in Java combines the current year object with a month passed as parameter to it to create a YearMonth object.
public YearMonth atMonth(int month)
Parameter: This method accepts a single parameter month. It is the month-of-year to use. It takes an integer value between 1 and 12 and cannot be NULL.
Return Value: It returns a YearMonth object formed by the current year object and a valid month passed as parameter to the function.
Exception: This method throws a DateTimeException, if the month passed to it as parameter is invalid.
Below programs illustrate the atMonth(int) method of Year in Java:
Program 2: To illustrate Exception.
java.time.DateTimeException: Invalid value for MonthOfYear (valid values 1 - 12): 16
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.