public static void main(String[] args) {
LocalDate nowDate = LocalDate.now();
System.out.println("本年第一天:" + nowDate.with(TemporalAdjusters.firstDayOfYear()));
System.out.println("本年最后一天:" + nowDate.with(TemporalAdjusters.lastDayOfYear()));
// 本季度第一天
int month = nowDate.getMonthValue();
LocalDate firstDayOfQuarter;
if (month <= 3) {
firstDayOfQuarter = LocalDate.of(nowDate.getYear(), Month.JANUARY, 1);
} else if (month <= 6) {
firstDayOfQuarter = LocalDate.of(nowDate.getYear(), Month.APRIL, 1);
} else if (month <= 9) {
firstDayOfQuarter = LocalDate.of(nowDate.getYear(), Month.JULY, 1);
} else {
firstDayOfQuarter = LocalDate.of(nowDate.getYear(), Month.OCTOBER, 1);
}
System.out.println("本季度第一天:" + firstDayOfQuarter);
System.out.println("本季度最后一天:" + nowDate.plusMonths(3 - nowDate.getMonthValue() % 3).with(TemporalAdjusters.lastDayOfMonth()));
System.out.println("本月第一天:" + nowDate.with(TemporalAdjusters.firstDayOfMonth()));
System.out.println("本月最后一天:" + nowDate.with(TemporalAdjusters.lastDayOfMonth()));
// DayOfWeek可指定一周从星期几开始
System.out.println("本周第一天:" + nowDate.with(DayOfWeek.MONDAY));
System.out.println("本周最后一天:" + nowDate.with(DayOfWeek.SUNDAY));
}
结果示例: