java 3天之后的时间计算
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class testdate {
public static String add3Day(Date date) throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(date);//Date转换为Calendar
cal.add(Calendar.DATE, 3);//将日期往后推3天,减少3天则-3. 月增加则Calendar.MONTH
String after = sdf.format(cal.getTime());//Calendar转换为Date,再转换为String
return after;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date td = null;
try {
td = sdf.parse("2016-11-04 11:41:00.332");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
System.out.println(add3Day(td));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}