提供了非常多处理日期相关的函数:
使用示例:
/**
* JCccc
* @param args
*/
public static void main(String[] args) {
DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime now = LocalDateTime.now();
//获取当月第一天
System.out.println("当月第一天:" + now.with(TemporalAdjusters.firstDayOfMonth()).format(pattern));
//获取下月第一天
System.out.println("下月第一天:" + now.with(TemporalAdjusters.firstDayOfNextMonth()).format(pattern));
//获取明年第一天
System.out.println("明年第一天:" + now.with(TemporalAdjusters.firstDayOfNextYear()).format(pattern));
//获取本年第一天
System.out.println("本年第一天:" + now.with(TemporalAdjusters.firstDayOfYear()).format(pattern));
//获取当月最后一天
System.out.println("当月最后一天:" + now.with(TemporalAdjusters.lastDayOfMonth()).format(pattern));
//获取本年最后一天
System.out.println("本年最后一天:" + now.with(TemporalAdjusters.lastDayOfYear()).format(pattern));
//获取当月第三周星期五
System.out.println("当月第三周星期五:" + now.with(TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.FRIDAY)).format(pattern));
//获取上周一
System.out.println("上周一:" + now.with(TemporalAdjusters.previous(DayOfWeek.MONDAY)).format(pattern));
//获取下周日
System.out.println("下周日:" + now.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)).format(pattern));
}
效果: