Java Data Type How to - Add one day to LocalDate and minus hours and minutes from LocalDateTime








Question

We would like to know how to add one day to LocalDate and minus hours and minutes from LocalDateTime.

Answer

import java.time.LocalDate;
import java.time.LocalDateTime;
/*from   www  .j  ava  2s .c o  m*/
public class Main {
  public static void main(String[] args) {
    LocalDate tomorrow = LocalDate.now().plusDays(1);

    // before 5 hours and 30 minutes
    LocalDateTime dateTime = LocalDateTime.now().minusHours(5).minusMinutes(30);

    System.out.println("additionSubtraction: tomorrow: " + tomorrow);
    System.out.println("additionSubtraction: dateTime: " + dateTime);

  }
}

The code above generates the following result.