/** * 得到X天后的时间(时间格式) * * @param date * @param day * @return */ public static Date getXDateAfterDate(Date date, int day) { Calendar now = Calendar.getInstance(); now.setTime(date); now.set(Calendar.DATE, now.get(Calendar.DATE) + day); return now.getTime(); }
/** * 得到X天后的时间(字符串格式) * * @param dateStr * @param day * @return */ public static String getXDateAfterDateStr(String dateStr, int day) { Calendar now = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d = null; try { d = df.parse(dateStr); now.setTime(d); now.set(Calendar.DATE, now.get(Calendar.DATE) + day); } catch (ParseException e) { e.printStackTrace(); } return df.format(now.getTime()); }