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<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; }
java 获取最近7天 最近今天的日期
private static Date getDateAdd(int days){ SimpleDateFormat s…
免责声明:文章内容不代表本站立场,本站不对其内容的真实性、完整性、准确性给予任何担保、暗示和承诺,仅供读者参考,文章版权归原作者所有。如本文内容影响到您的合法权益(内容、图片等),请及时联系本站,我们会及时删除处理。