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
最新推荐文章于 2024-04-16 10:41:35 发布