Adjust LocalDate to next monday
Description
The following code shows how to adjust LocalDate to next monday.
Example
//from w w w .j a va 2 s . c om
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.Year;
import java.time.temporal.TemporalAdjusters;
public class Main {
public static void main(String[] args) {
Month month = Month.valueOf("MAY");
LocalDate date = Year.now().atMonth(month).atDay(1).
with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
Month mi = date.getMonth();
while (mi == month) {
System.out.printf("%s%n", date);
date = date.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
mi = date.getMonth();
}
}
}
The code above generates the following result.