获取当前月,从上个月开始的最近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; }
标签:11,12,get,上个月,获取,cal,last12Months,Calendar 来源: https://www.cnblogs.com/ljmm/p/16625445.html