Java实现日期任意跳转

public static String DateOperation(String type, Date myDate, int num) {

String date = null;

SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");

try {
Calendar c = Calendar.getInstance();
c.setTime(myDate);
if (type.equals("0")){
c.add(Calendar.MONTH, 1);
myDate = c.getTime();
date = formatter.format(myDate);
String dt = date.substring(date.length()-2,date.length());
System.out.println("截取后的日期:[" + dt + "]");
int days = num - Integer.parseInt(dt);
System.out.println("相差天数:" + days);
c.add(Calendar.DATE, days);
myDate = c.getTime();
date = formatter.format(myDate);
}else if (type.equals("1")){
c.add(Calendar.DATE, num);
myDate = c.getTime();
date = formatter.format(myDate);
}
System.out.println("订单下次提醒日期:[" + date + "]");

} catch (Exception e1) {
e1.printStackTrace();
}
return date;
}
04-13 18:40