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

前端 未结 28 1783

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

    long timeadj = 24*60*60*1000;
    Date newDate = new Date (oldDate.getTime ()+timeadj);
    

    This takes the number of milliseconds since epoch from oldDate and adds 1 day worth of milliseconds then uses the Date() public constructor to create a date using the new value. This method allows you to add 1 day, or any number of hours/minutes, not only whole days.

提交回复
热议问题