import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Test {
/**
* @Title: changeDay
* @Description: TODO(获取自己传递过来时间的加减天数后的时间)
* @return Date 返回类型
*/
public static Date changeDay(Date date,int day){
Calendar calen = Calendar.getInstance();//得到当前时间
calen.setTime(date);
calen.add(Calendar.DATE, day); //
return calen.getTime();
}
/**
* @Title: changeDay
* @Description: TODO(获取当前日期加减后的时间)
* @return Date 返回类型
*/
public static Date changeDay(int day){
Calendar calen = Calendar.getInstance();
calen.setTime(new Date());
calen.add(Calendar.DATE, day);
return calen.getTime();
}
public static void main(String[] args) throws Exception {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String t1=format.format(changeDay(-1));
System.out.println(t1);
Date d=format.parse("2014-01-02 12:30:30");
String t2=format.format(changeDay(d,-1));
System.out.println(t2);
}
}