Java程序通过TemporalAdjusters类将LocalDate调整为一年中的最后一天
让我们先设置一个日期:
LocalDate localDate = LocalDate.of(2019, Month.FEBRUARY, 11);
现在,将LocalDate调整为一年的最后一天:
LocalDate day = localDate.with(TemporalAdjusters.lastDayOfYear());
示例
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
public class Demo {
public static void main(String[] args) {
LocalDate localDate = LocalDate.of(2019, Month.FEBRUARY, 11);
System.out.println("Current Date = "+localDate);
System.out.println("Current Month = "+localDate.getMonth());
LocalDate day = localDate.with(TemporalAdjusters.firstDayOfMonth());
System.out.println("First day of month = "+day);
day = localDate.with(TemporalAdjusters.lastDayOfMonth());
System.out.println("Last day of month = "+day);
day = localDate.with(TemporalAdjusters.lastDayOfYear());
System.out.println("Last day of year = "+day);
day = localDate.with(TemporalAdjusters.firstDayOfNextMonth());
System.out.println("First day of next month = "+day);
}
}输出结果
Current Date = 2019-02-11 Current Month = FEBRUARY First day of month = 2019-02-01 Last day of month = 2019-02-28 Last day of year = 2019-12-31 First day of next month = 2019-03-01
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短