public class Test {
public static void main(String[] args)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
Date date=new Date();//取时间
System.out.println("当前时间:"+sdf.format(date));
Calendar calendar=new GregorianCalendar();
calendar.setTime(date);
calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动
date=calendar.getTime();
//这个时间就是日期往后推一天的结果
System.out.println("后一天时间:"+sdf.format(date));
Calendar calendarBefore=new GregorianCalendar();
calendarBefore.setTime(date);
calendarBefore.add(calendarBefore.DATE,-1);//把日期往前推一天.整数往后推,负数往前移动
date=calendarBefore.getTime();
//这个时间就是日期往前推一天的结果
System.out.println("前一天时间:"+sdf.format(date));
}
}