The atDay() method of Year class in Java combines the current year with a day-of-year passed as parameter to it to create a LocalDate.
public LocalDate atDay(int dayOfYear)
Parameter: This method accepts a single parameter dayOfYear. It is the day-of-year to use. It can take values from 1 to 365-366.
Return Value: It returns a Local Date formed by the current year and a date of year passed as parameter to the function.
Exception: This method throws a DateTimeException, if the day of year passed in the parameter is not valid, that is zero or less, 366 or greater or equal to 366 and the current year is not a leap year.
Below programs illustrate the atDay() method of Year in Java:
Program 2: To illustrate Exception.
java.time.DateTimeException: Invalid value for DayOfYear (valid values 1 - 365/366): 367
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.