The TemporalAdjuster returned by the next (DayOfWeek dayOfWeek)
method of the TemporalAdjusters You can change the date of LocalDate
to the date of the next x day using an instance of: //docs.oracle.com/javase/jp/8/docs/api/java/time/temporal/TemporalAdjuster.html) ..
Sample code
LocalDate d = LocalDate.of(2019, 3, 25).with(TemporalAdjusters.next(DayOfWeek.MONDAY));
LocalDate d2 = LocalDate.of(2019, 3, 29).with(TemporalAdjusters.next(DayOfWeek.valueOf("MONDAY")));
LocalDate d3 = LocalDate.of(2019, 3, 31).with(TemporalAdjusters.next(DayOfWeek.of(1)));
System.out.println(d.toString());
System.out.println(d2.toString());
System.out.println(d3.toString());
output
2019-04-01
2019-04-01
2019-04-01
If the LocalDate date is already that day of the week, it will be set to the next week's date.
Using nextOrSame (DayOfWeek dayOfWeek)
does nothing if LocalDate is already that day of the week.
sample
LocalDate d = LocalDate.of(2019, 3, 25).with(TemporalAdjusters.nextOrSame(DayOfWeek.MONDAY));
LocalDate d2 = LocalDate.of(2019, 3, 29).with(TemporalAdjusters.nextOrSame(DayOfWeek.valueOf("MONDAY")));
LocalDate d3 = LocalDate.of(2019, 3, 31).with(TemporalAdjusters.nextOrSame(DayOfWeek.of(1)));
output
2019-03-25
2019-04-01
2019-04-01
Recommended Posts