1. 获取前一天日期
if(StringUtils.isBlank(curDate)) { curDate=DateTime.now().toDateStr();}// 获取前一天日期String date = LocalDate.parse(curDate) .minusDays(1) .format(DateTimeFormatter.ofPattern("yyyyMMdd"));
Date dBefore = new Date();SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");Calendar calendar = Calendar.getInstance();calendar.setTime(dBefore);calendar.add(Calendar.DATE, -1);curDate = format.format(calendar.getTime());
2.获取前三个月日期
Date dBefore = new Date();Calendar calendar = Calendar.getInstance();calendar.setTime(dBefore);calendar.add(Calendar.MONDAY, -3);curDate = format.format(calendar.getTime());
if(StringUtils.isBlank(curDate)) { curDate=DateTime.now().toDateStr();}String date = LocalDate.parse(curDate) .minusMonths(3) .format(DateTimeFormatter.ofPattern("yyyyMMdd"));
来源地址:https://blog.csdn.net/HDHGJDFGHJDF/article/details/129275960