服务需要订购一个月,订购一个月 不等于增加 30天;若是1,3,5的话应该 31天,要善用
Calendar
public static void main(String[] args) throws ParseException {
String dateStr = "2023-05-01 09:00:00";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = dateFormat.parse(dateStr);
Calendar calendar1 = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();
calendar1.setTime(date);
calendar2.setTime(date);
calendar1.add(Calendar.MONTH, 1); //加一个月
calendar2.add(Calendar.DATE, 30); //加30天
System.out.println(dateFormat.format(calendar1.getTime()));
System.out.println(dateFormat.format(calendar2.getTime()));
}
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/p/17651910.html