获取当前月,从上个月开始的最近12个月


    /**
     * 获取当前月,从上个月开始的最近12个月
     * @return
     */
    public static String[] getLast12Months(){
        String[] last12Months = new String[12];
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < 12; i++) {
            if (cal.get(Calendar.MONTH) - i < 1) {
                //last12Months[11 - i] = cal.get(Calendar.YEAR) - 1 + "-" + fillZero((cal.get(Calendar.MONTH) - i + 12 * 1));
                last12Months[11 - i] = cal.get(Calendar.YEAR) - 1 + fillZero((cal.get(Calendar.MONTH) - i + 12 * 1));
            } else {
                //last12Months[11 - i] = cal.get(Calendar.YEAR) + "-" + fillZero((cal.get(Calendar.MONTH) - i));
                last12Months[11 - i] = cal.get(Calendar.YEAR) + fillZero((cal.get(Calendar.MONTH) - i));
            }
            //System.out.println(last12Months[11 - i]);
        }
        return last12Months;
    }

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/282234.html

(0)
上一篇 2022年8月25日
下一篇 2022年8月25日

相关推荐

发表回复

登录后才能评论