java工具类(四)之实现日期随意跳转

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;
}
上一篇:3D转弯保护区长啥样?


下一篇:linux服务器规格查看