Java 编程:列出指定月份所有星期一
package step6;
import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters;
/********** Begin *********/ public class TestMonday {
public static void main(String[] args) {
LocalDate date = LocalDate.of(2022, 4, 1);
LocalDate firstMonday = date.with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
LocalDate lastMonday = date.with(TemporalAdjusters.lastInMonth(DayOfWeek.MONDAY));
System.out.println('For the month of APRIL all Monday are:');
while (!firstMonday.isAfter(lastMonday)) {
System.out.println(firstMonday);
firstMonday = firstMonday.plusWeeks(1);
}
}
} /********** End *********/
原文地址: https://www.cveoy.top/t/topic/nITx 著作权归作者所有。请勿转载和采集!