JDK8 LocalDate获取月初月末
程序员文章站
2022-05-15 10:02:11
...
1.获取月初月末
public static void main(String[] args) {
String count_date="2020-02-05";
//获取月初
LocalDate monthOfFirstDate=LocalDate.parse(count_date,
DateTimeFormatter.ofPattern("yyyy-MM-dd")).with(TemporalAdjusters.firstDayOfMonth());
//获取月末
LocalDate monthOfLastDate=LocalDate.parse(count_date,
DateTimeFormatter.ofPattern("yyyy-MM-dd")).with(TemporalAdjusters.lastDayOfMonth());
TemporalAdjusters.firstDayOfMonth();
System.out.println(monthOfFirstDate);
System.out.println(monthOfLastDate);
}
输出:
2020-02-01
2020-02-29
上一篇: php拼字符串 请教