java获取前四个季度结束日期_JAVA使用LocalDate获取当前日期所在季度的开始日期和结束日期...

需要使用jdk1.8及以上

/**

* 获取当前日期所在季度的开始日期和结束日期

* 季度一年四季, 第一季度:1月-3月, 第二季度:4月-6月, 第三季度:7月-9月, 第四季度:10月-12月

* @param isFirst true表示查询本季度开始日期 false表示查询本季度结束日期

* @return

*/

public static LocalDate getStartOrEndDayOfQuarter(Boolean isFirst){

LocalDate today=LocalDate.now();

LocalDate resDate = LocalDate.now();

if (today == null) {

today = resDate;

}

Month month = today.getMonth();

Month firstMonthOfQuarter = month.firstMonthOfQuarter();

Month endMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2);

if (isFirst) {

resDate = LocalDate.of(today.getYear(), firstMonthOfQuarter, 1);

} else {

resDate = LocalDate.of(today.getYear(), endMonthOfQuarter, endMonthOfQuarter.length(today.isLeapYear()));

}

return resDate;

}

标签:JAVA,resDate,Month,日期,firstMonthOfQuarter,LocalDate,today

来源: https://www.cnblogs.com/pxblog/p/13935746.html


版权声明:本文为weixin_31437187原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。