Java程序通过TemporalAdjusters类将Adjust LocalDate调整为下个月的第一天
我们首先设置一个日期-
LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15);
现在,将LocalDate调整为下个月的第一天-
LocalDate day = localDate.with(TemporalAdjusters.firstDayOfNextMonth());
示例
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.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 First day of next month = 2019-07-01
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短