I use the code below to change the date format of the date. But the result changes to different date, it becomes 12/27/2021. When I checked it, it says it uses Gregorian Calendar. Anyone know how to fix this.
String date = "23-03-2021";
Date d = new SimpleDateFormat("dd-MM-YYYY").parse(date);
SimpleDateFormat outputFormat = new SimpleDateFormat("MM/dd/YYYY");
String paymentdate = outputFormat.format(d);
System.out.println(paymentdate);
Actual:
12/27/2021
Expected:
03/23/2021