Java 获取当月天数、上月最大天数


今天正好是3月,可以测试特殊月份的2月

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8")); // 设置时区
        SimpleDateFormat oSdf = new SimpleDateFormat ("yyyy-MM-dd");
        String format = oSdf.format(new Date()); 
        cal.setTime(oSdf.parse(format)); // 设置时间
        int thisMonth = cal.get(Calendar.DAY_OF_MONTH); // 得到当月
        cal.add(Calendar.MONTH, -1); // 得到上月月份
        int lastMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 得到上月总天数


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM