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;
    }

 


LocalDate轉換成Date參考:https://www.cnblogs.com/pxblog/p/13935825.html

JAVA獲取指定日期的一天的開始時刻(時間)和結束時刻(時間):https://www.cnblogs.com/pxblog/p/13203471.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM