/**
* 获取过去或者未来 任意天内的日期数组
* @param intervals intervals天内
* @return 日期数组
*/
public static ArrayList test(int intervals ) {
ArrayList pastDaysList = new ArrayList<>();
ArrayList fetureDaysList = new ArrayList<>();
for (int i = 0; i <intervals; i++) {
pastDaysList.add(getPastDate(i));
fetureDaysList.add(getFetureDate(i));
}
return pastDaysList;
}
/**
* 获取过去第几天的日期
*
* @param past
* @return
*/
public static String getPastDate(int past) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
Date today = calendar.getTime();
SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd”);
String result = format.format(today);
Log.e(null, result);
return result;
}
/**
* 获取未来 第 past 天的日期
* @param past
* @return
*/
public static String getFetureDate(int past) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
Date today = calendar.getTime();
SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd”);
String result = format.format(today);
Log.e(null, result);
return result;
}