Java 如何判斷月份以及月份包含的天數?


 

java編程 判斷月份,判斷天數?

   private Integer calDayNumbersByMonth(Integer year, Integer month) throws Exception {
        Tools.log("輸入的月份是:" + month);
        if (month != null) {
            switch (month) {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    return 31;
                //對於2月份需要判斷是否為閏年
                case 2:
                    if (year % 4 == 0 && year % 100 != 0) {
                        return 29;
                    } else if (year % 400 == 0){
                        return 29;
                    } else {
                        return 28;
                    }
                case 4:
                case 6:
                case 9:
                case 11:
                    return 30;
                default:
                    return null;
            }
        } else {
            return null;
        }
    }

 


免責聲明!

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



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