JAVA日期加减的两种方法
SimpleDateFormat和Calender
1、Calender
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());//设置起时间
//cal.add(Calendar.YEAR, 1);//增加一年
//cal.add(Calendar.DATE, 1);//增加一天
cal.add(Calendar.DATE, -10);//减10天
//cal.add(Calendar.MONTH, 1);//增加一个月
System.out.println(cal.getTime());
2、SimpleDateFormat
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
System.out.println("今天:"+sdf.format(new Date()));
System.out.println("两天前:" + sdf.format(new Date(date.getTime() - 2 * 24 * 60 * 60 * 1000)));
System.out.println("三天后:" + sdf.format(new Date(date.getTime() + 3 * 24 * 60 * 60 * 1000)));