This method returns a new copy of this local date, with day-of-year field replaced with the provided 'dayOfYear' value.
If the provided dayOfYear is invalid, an exception is thrown.
Invalid value of year will throw DateTimeException.
package com.logicbig.example.localdate;
import java.time.LocalDate;
public class WithDayOfYearExample2 {
public static void main (String... args) {
LocalDate d = LocalDate.of(2016, 2, 10);
LocalDate d1 = d.withDayOfYear(367);
System.out.println(d1);
}
}
Output
Caused by: java.time.DateTimeException: Invalid value for DayOfYear (valid values 1 - 365/366): 367
at java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
at java.time.temporal.ChronoField.checkValidValue(ChronoField.java:703)
at java.time.LocalDate.ofYearDay(LocalDate.java:287)
at java.time.LocalDate.withDayOfYear(LocalDate.java:1118)
at com.logicbig.example.localdate.WithDayOfYearExample2.main(WithDayOfYearExample2.java:15)
... 6 more