I am trying to convert a date of the format 2019-12-30
to a date with format 30-12-2019
and for this I thought of using DateTimeFormatter
and I have the following code for this:
LocalDate date = LocalDate.parse("2019-12-30");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY");
System.out.println(formatter.format(date));
However, to my surprise, this returns an output:
30-12-2020
instead of the expected 30-12-2019
. If the date is set to 2019-11-30
, it correctly returns 30-11-2019
. I am doing something terribly wrong but I am not able to figure out what exactly. Can someone please help?