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