java中日期增加一天或一月的方法

版权声明:版权所有,违者必究 https://blog.csdn.net/weixin_39921821/article/details/88250718

直接上代码:

//实现日期加一天的方法
    public static String addDay(String s, int n) {   
        try {   
                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");   
  
                 Calendar cd = Calendar.getInstance();   
                 cd.setTime(sdf.parse(s));   
                 cd.add(Calendar.DATE, n);//增加一天   
                 //cd.add(Calendar.MONTH, n);//增加一个月   
  
                 return sdf.format(cd.getTime());   
       
             } catch (Exception e) {   
                 return null;   
             }   
     }  

猜你喜欢

转载自blog.csdn.net/weixin_39921821/article/details/88250718