Java程序,通过TemporalAdjusters类将LocalDate调整为每月的第一天
我们首先设置一个日期-
LocalDate localDate = LocalDate.of(2019, Month.APRIL, 10);
现在,将LocalDate调整为每月的第一天-
LocalDate day = localDate.with(TemporalAdjusters.firstDayOfMonth());
示例
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.APRIL, 10);
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);
}
}输出结果
Current Date = 2019-04-10 Current Month = APRIL First day of month = 2019-04-01
热门推荐
10 节日祝福语幽默简短的
11 入伙英文祝福语大全简短
12 祝福语赠言给老师简短
13 日语送考祝福语简短
14 考试祝福语日文简短版
15 女朋友祝福语简短新年
16 周末祝福语正能量简短
17 月子小孩祝福语大全简短
18 参加儿子大学祝福语简短