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

前端 未结 28 1832

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

    Java 8 added a new API for working with dates and times.

    With Java 8 you can use the following lines of code:

    // parse date from yyyy-mm-dd pattern
    LocalDate januaryFirst = LocalDate.parse("2014-01-01");
    
    // add one day
    LocalDate januarySecond = januaryFirst.plusDays(1);
    

提交回复
热议问题