How can I increment a date by one day in Java?

前端 未结 28 1793

I\'m working with a date in this format: yyyy-mm-dd.

How can I increment this date by one day?

28条回答
  •  独厮守ぢ
    2020-11-21 07:24

    You can use this package from "org.apache.commons.lang3.time":

     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
     Date myNewDate = DateUtils.addDays(myDate, 4);
     Date yesterday = DateUtils.addDays(myDate, -1);
     String formatedDate = sdf.format(myNewDate);  
    

提交回复
热议问题