Java程序通过TemporalAdjusters类将LocalDate调整为每月的最后一天
让我们先设置一个日期:
LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15)
现在,将LocalDate调整为每月的最后一天;
LocalDate day = localDate.with(TemporalAdjusters.lastDayOfMonth());
示例
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.JUNE, 15);
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.firstDayOfNextMonth());
System.out.println("First day of next month = "+day);
}
}输出结果
Current Date = 2019-06-15 Current Month = JUNE First day of month = 2019-06-01 Last day of month = 2019-06-30 First day of next month = 2019-07-01
热门推荐
10 简短的出行工作祝福语
11 朋友孩子考试祝福语简短
12 3岁孩子祝福语简短
13 虎年公司祝福语简短的
14 亲戚生日红包祝福语简短
15 给表弟的祝福语简短
16 新年祝福语简短给孩子
17 简短对公司的祝福语
18 许嵩生日祝福语简短