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

前端 未结 28 1830

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:11

    java.time

    On Java 8 and later, the java.time package makes this pretty much automatic. (Tutorial)

    Assuming String input and output:

    import java.time.LocalDate;
    
    public class DateIncrementer {
      static public String addOneDay(String date) {
        return LocalDate.parse(date).plusDays(1).toString();
      }
    }
    

提交回复
热议问题