package controller;
import java.time.LocalDate;
import java.time.Month;
public class Demo2 {
public static void main(String[] args) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
currentDate = currentDate.minusMonths(3);
// 计算上个季度的月份范围
Month startMonth = getStartMonthOfLastQuarter(currentDate.getMonth());
Month endMonth = startMonth.plus(2);
LocalDate firstDay = LocalDate.of(currentDate.getYear(),startMonth,1);
LocalDate endDay = LocalDate.of(currentDate.getYear(),endMonth,endMonth.length(currentDate.isLeapYear()));
System.out.println("开始日期:"+firstDay);
System.out.println("结束日期:"+endDay);
}
public static Month getStartMonthOfLastQuarter(Month currentMonth){
int currentMonthValue = currentMonth.getValue();
int startMonthValue = (currentMonthValue - 1)/3*3+1;
return Month.of(startMonthValue);
}
}
java中获取某个日期前一个季度的第一天或者最后一天日期
最新推荐文章于 2024-05-11 15:10:09 发布