java 获取最近7天 最近今天的日期
时间:2021-12-02 作者:匿名
private static Date getDateAdd(int days){ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = 域名nstance(); 域名(域名OF_MONTH, -days); return 域名ime(); } private static List<String> getDaysBetwwen(int days){ //最近几天日期 List<String> dayss = new ArrayList<>(); Calendar start = 域名nstance(); 域名ime(getDateAdd(days)); Long startTIme = 域名imeInMillis(); Calendar end = 域名nstance(); 域名ime(new Date()); Long endTime = 域名imeInMillis(); Long oneDay = 1000 * 60 * 60 * 24l; Long time = startTIme; while (time <= endTime) { Date d = new Date(time); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 域名tln(域名at(d)); 域名(域名at(d)); time += oneDay; } return dayss; }