日期的加减操作
通过重载的方法来实现独立修改年月日如果是前几个月可以使用负数
public static String modifyDate(Date date, int year,int month,int day){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Calendar calendar = new GregorianCalendar();
calendar.add(calendar.MONTH,year);
calendar.add(calendar.MONTH,month);
calendar.add(calendar.DATE,day);//把日期往后增加一天.整数往后推,负数往前移动
String startDate=sf.format(calendar.getTime());
return startDate;
}
public static String modifyDate(Date date,int month,int day) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Calendar calendar = new GregorianCalendar();
// calendar.add(calendar.MONTH,year);
calendar.add(calendar.MONTH,month);
calendar.add(calendar.DATE,day);//把日期往后增加一天.整数往后推,负数往前移动
String startDate=sf.format(calendar.getTime());
return startDate;
}
public static String modifyDate(Date date, int day){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Calendar calendar = new GregorianCalendar();
//calendar.add(calendar.MONTH,year);
// calendar.add(calendar.MONTH,month);
calendar.add(calendar.DATE,day);//把日期往后增加一天.整数往后推,负数往前移动
String startDate=sf.format(calendar.getTime());
return startDate;
}