0

smsRequest.setEndDate(1 day later); /// TODO 1 day later

I want to set the date after 1 day to the variable endDate, which is held as a string and of type ddMMyyyyHHmm. How can I give?

  • 1
    Holding your end date and time in a `String`? Don’t! Use a `LocalDateTime` or another datetime object. Are you keeping numbers and Boolean values in strings too? ;-P And use the `plusDays` method of `LocalDateTIme` to add a day. – Ole V.V. Sep 06 '22 at 05:34
  • Actually, it wasn't my choice. :( Since the outbound service expects a value like this, I'm trying to do it accordingly. – stickyfingers Sep 06 '22 at 05:43
  • 1
    I consider your question too broad for Stack Overflow. Please search for how to add 1 day to a date and time and for how to format the result of that into a string in the format you mention. It’s described in thousands of places. During your search ignore pages and answers suggesting to use the old and poorly designed classes like `Date` and `SimpleDateFormat`. Go for those using [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Sep 06 '22 at 06:05
  • 1
    A starting point could be something like `ZonedDateTime.now(ZoneId.of("Antarctica/Casey")).plusDays(1).format(DateTimeFormatter.ofPattern("ddMMuuuuHHmm"))`. It just gave `070920221411`. – Ole V.V. Sep 06 '22 at 06:12
  • 1
    You're a great person, thank yo! It worked that way. I never know if I should use a format like this. I guess I need to learn how to research it in the first place. – stickyfingers Sep 06 '22 at 14:26
  • Always search Stack Overflow thoroughly before posting. Your issues have been addressed many many times already. – Basil Bourque Sep 07 '22 at 07:56

0 Answers0