/**
* 今天起 近7天日期 后七天
* @param days=6
* @return
*/
public static List<String> getDaysBetwwen(int days){ //最近几天日期
List<String> dayss = new ArrayList<>();
Calendar start = Calendar.getInstance();
start.setTime(new Date());
Long startTIme = start.getTimeInMillis();
Calendar end = Calendar.getInstance();
end.setTime(getDateAdd(days));
Long endTime = end.getTimeInMillis();
Long oneDay = 1000 * 60 * 60 * 24l;
Long time = startTIme;
while (time <= endTime) {
Date d = new Date(time);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(d));
dayss.add(df.format(d));
time += oneDay;
}
return dayss;
}
private static Date getDateAdd(int days){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, +days);
}
/**
* 昨天八点
* @return
*/
public static String getYesterday(){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//日期格式
Calendar cale = Calendar.getInstance(); // 取当前日期。
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,8);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
calendar.add(Calendar.DAY_OF_YEAR,-1);
Date date = calendar.getTime();
return format.format(date);
}
/**
* 今天起 近7天日期 后7天
* @param days
* @return
*/
public static List<String> getDaysBetwwen(int days){ //最近几天日期
List<String> dayss = new ArrayList<>();
Calendar start = Calendar.getInstance();
start.setTime(getDateAdd(days));
Long startTIme = start.getTimeInMillis();
Calendar end = Calendar.getInstance();
end.setTime(new Date());
Long endTime = end.getTimeInMillis();
Long oneDay = 1000 * 60 * 60 * 24l;
Long time = startTIme;
while (time <= endTime) {
Date d = new Date(time);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(d));
dayss.add(df.format(d));
time += oneDay;
}
return dayss;
}
private static Date getDateAdd(int days){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, -days);
return c.getTime();
}