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();}private static List getDaysBetwwen(int days){ List 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;}
java获取7天后的日期_java 获取最近7天 最近今天的日期
最新推荐文章于 2024-08-18 03:06:03 发布