SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try{
Date d = sdf.parse("2018-01-31");
Calendar cld = Calendar.getInstance();
cld.setTime(d);
cld.add(Calendar.MONTH, 1);
Date d2 = cld.getTime();
System.out.println(sdf.format(d)+"加一月:"+sdf.format(d2));
//闰年的情况
d = sdf.parse("2016-01-31");
cld = Calendar.getInstance();
cld.setTime(d);
cld.add(Calendar.MONTH, 1);
d2 = cld.getTime();
System.out.println(sdf.format(d)+"加一月:"+sdf.format(d2));
}catch(Exception e){
e.printStackTrace();
}
JAVA Calendar日期加1
最新推荐文章于 2022-07-03 16:07:39 发布