获取四个季度的最后一天

package test;
import java.time.LocalDate;
import java.time.Month;
import java.time.Year;

public class lastjidu {
    public static void main(String[] args) {

        LocalDate lastDayOfCurrentQuarter = getLastDayOfCurrentQuarter();
        System.out.println("当前季度的最后一天是:" + lastDayOfCurrentQuarter);






    }

    public static LocalDate getLastDayOfCurrentQuarter() {
        LocalDate currentDate = LocalDate.now();

//         直接可以获得 月份(1-12)
        Month currentMonth = currentDate.getMonth();
        int currentQuarter = (currentMonth.getValue() -1) / 3 +1;
        System.out.println(currentMonth.getValue());//9 月份
        System.out.println(currentQuarter);//4 第4季度

//    Month 类型
        Month lastMonthOfQuarter = Month.of((currentQuarter ) * 3 );
        System.out.println(lastMonthOfQuarter);//DECEMBER
//        int 类型
        int lastMonthOfQuarter_geshu = Month.of((currentQuarter ) * 3 ).getValue();
        System.out.println(lastMonthOfQuarter_geshu);//12 季度最后一天

//        currentDate.withMonth( ) 的参数为int 类型  更改 currentDate的月份
//        withDayOfMonth            更改 currentDate的天数
//        lastMonthOfQuarter.length(false)   返回当前月的最大天数,false是当为二月时是否为闰年
        LocalDate lastDayOfQuarter = currentDate.withMonth(lastMonthOfQuarter_geshu).withDayOfMonth(lastMonthOfQuarter.length(false));



        return lastDayOfQuarter;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值