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

前端 未结 28 1861

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

    I prefer to use DateUtils from Apache. Check this http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/time/DateUtils.html. It is handy especially when you have to use it multiple places in your project and would not want to write your one liner method for this.

    The API says:

    addDays(Date date, int amount) : Adds a number of days to a date returning a new object.

    Note that it returns a new Date object and does not make changes to the previous one itself.

提交回复
热议问题