代码片段如下
/** * 获取x天前的日期 */ private static String getDay(int day){ String dayTmp = ""; Date dateNow = new Date(); //获取日历 Calendar calendar = Calendar.getInstance(); calendar.setTime(dateNow); calendar.add(Calendar.DAY_OF_MONTH,-day); Date dateBefore=calendar.getTime(); //转换格式 SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String beforeDay = df.format(dateBefore); //赋值 dayTmp = beforeDay; System.out.println("前day天时间:"+dayTmp); return dayTmp; }