public static void main(String[] args)
{ //月份加减
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
Calendar calendar=Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH,3);//日期加3个月
Date dt=calendar.getTime();
String reStr = sdf.format(dt);
System.out.println(reStr);
}
{ //月份加减
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
Calendar calendar=Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH,3);//日期加3个月
Date dt=calendar.getTime();
String reStr = sdf.format(dt);
System.out.println(reStr);
}
本文介绍如何使用Java中的SimpleDateFormat和Calendar类来实现日期的月份加减操作,并给出具体示例代码,演示如何将当前日期加上三个月。
332

被折叠的 条评论
为什么被折叠?



