Java 获取最近12个月的时间日期

代码:

    /**
     *  JCccc
     * @return
     */
    public static List getLast12Months() {
        List monthList = new ArrayList<>();
        Calendar currentDate = Calendar.getInstance();
        for (int i = 0; i < 12; i++) {
            String monthStr;
            if ((currentDate.get(Calendar.MONTH) + 1) < 10) {
                monthStr = "0" + (currentDate.get(Calendar.MONTH) + 1);
            } else {
                monthStr = String.valueOf((currentDate.get(Calendar.MONTH) + 1));
            }
            monthList.add(currentDate.get(Calendar.YEAR) + "-" + monthStr);
            currentDate = (Calendar) currentDate.clone();
            currentDate.add(Calendar.MONTH, -1);
        }
        return monthList;
    }

你可能感兴趣的:(java大乱炖,java,近12个月,时间)