1 year ago
#269671
Aldaris
Java DateTimeFormatter - Adding days sometimes provides a wrong result
Currently we have implemented the following:
LocalDateTime actualDate = LocalDateTime.now();
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd.MM.yyyy");
String fromDate = format.format(actualDate.plusDays(15));
String toDate = format.format(actualDate.plusDays(30));
Most of the time, it works perfectly fine. Sometimes, something wild appears as a Date - for example:
the toDate was correctly calculated to 09.04.2022 - but the fromDate was calculated as 02.20.9032, which seems totally odd. Especially, as it only occurs occasionally, it is hard to understand what exactly is going wrong here.
I would kindly appreciate any advice or help on the same. If plusDays(15) works, it seems odd why plusDays(30) suddenly shouldn't and viceversa... and it does only rarely happen to be wrong.
java
datetime
datetimeformatter
0 Answers
Your Answer