1、获取当前日期N天之后的日期(N为正数则后推,N为负数则向前推)
public static String afterNDay(int n){
Calendar c=Calendar.getInstance();
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
c.setTime(new Date());
c.add(Calendar.DATE,n);
Date d2=c.getTime();
String s=df.format(d2);
return s;
}
2、获取某日N天之后的日期(N为正数则后推,N为负数则向前推)
public static String afterNDay(String specifiedDay,int n){
Calendar c = Calendar.getInstance();
Date date=null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day=c.get(Calendar.DATE);
c.set(Calendar.DATE,day+n);
String afterNDay=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return afterNDay;、
}