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