48

I want to modify LocalDateTime.now() by adding a certain amount of minutes to it. How do I do that?

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
  • Do you mean to say the system's date and time? – Blip May 21 '15 at 13:13
  • 7
    `LocalDateTime fiveMinutesLater = LocalDateTime.now().plusMinutes(5)` ? Assuming that LocalDateTime is from the Joda framework. – Henrik Aasted Sørensen May 21 '15 at 13:14
  • I belive that is what I was looking for, Henrik. Thank you! –  May 21 '15 at 13:17
  • 2
    I'm quite new to programming and especially java. I did see `plusMinutes` but I had no idea it had to be appended to `LocalDateTime.now()` like that. –  May 21 '15 at 13:20
  • @Pshemo He missed it because it does not exist in Java 8 (https://i.imgur.com/DYwLU30.png) – Ian Boyd Jul 06 '22 at 20:19
  • @IanBoyd Your example is about `LocalDate` which doesn't include *time* of the day, which is why there is no methods for minutes. OP example is about `LocalDateTime` which had [`plusMinutes(long minutes)` in Java 8](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#plusMinutes-long-). – Pshemo Jul 06 '22 at 21:42

1 Answers1

100

If you are using java 8 then you can still use the same syntax

LocalDateTime fiveMinutesLater = LocalDateTime.now().plusMinutes(5)
Raghuveer
  • 2,859
  • 7
  • 34
  • 66
  • Definitely worked for me. Below is my example: {String currentDate = LocalDateTime.now().plusMinutes(5).format(DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm"));} – Erol Erdogan Aug 10 '21 at 11:51