java加减天数

指定日期的加减天数

public static String setDay(int num,String newDate) throws ParseException{
                 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                 Date  currdate = format.parse(newDate);
                 System.out.println("现在的日期是:" + format.format(currdate));
                 Calendar ca = Calendar.getInstance();
                 ca.set(Integer.parseInt(newDate.split("-")[0]), Integer.parseInt(newDate.split("-")[1]), Integer.parseInt(newDate.split("-")[2]));
                 ca.add(Calendar.DATE, num);// num为增加的天数,可以改变的
                 currdate = ca.getTime();
                 String enddate = format.format(currdate);
                 System.out.println("增加天数以后的日期:" + enddate);
                 return enddate;
             }

setDay(1,"2017-02-20");

原文地址:https://www.cnblogs.com/guoyansi19900907/p/6434474.html