/**
* 获取当前月,从上个月开始的最近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/tech/pnotes/282234.html