/**
* 获取最近7天
*/
public static List getSevenDay() {
Map<String, List> map = new HashMap();
List lastSevenDay = new ArrayList();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
for (int i=0;i<7;i++){
cal.add(Calendar.DAY_OF_MONTH, -1);
lastSevenDay.add(i, sdf.format(cal.getTime()));
}
return lastSevenDay;
}
/**
* 获取最近12个月
*/
public static Map<String, List> get12Month() {
Map<String, List> map = new HashMap();
List last12Months = new ArrayList();
List<String> xAxis = new ArrayList<>();
Calendar cal = Calendar.getInstance();
//如果当前日期大于二月份的天数28天或者29天会导致计算月份错误,会多出一个三月份,故设置一个靠前日期解决此问题
cal.set(Calendar.DAY_OF_MONTH, 1);
for (int i = 0; i < 12; i++) {
xAxis.add(i, (cal.get(Calendar.MONTH) + 1)+"月");
last12Months.add(i, cal.get(Calendar.YEAR)+""+ ((cal.get(Calendar.MONTH) + 1)<10 ? "0"+(cal.get(Calendar.MONTH) + 1):(cal.get(Calendar.MONTH) + 1)));
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1); //逐次往前推1个月
}
map.put("last12Months", last12Months);
map.put("xAxis", xAxis);
return map;
}