Use yyyy instead of YYYY because Y represents the week of year or week year whereas y represents only year.
According to Java Docs on Week Of Year and Week Year :
A week year is in sync with a WEEK_OF_YEAR cycle. All weeks between
the first and last weeks (inclusive) have the same week year value.
Therefore, the first and last days of a week year may have different
calendar year values.
Modified code :
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);
Output :
03/23/2021
Don't use java.util.Date as it is deprecated and it will be removed in the future. Better use classes from java.time package.
Equivalent code using java.time classes :
String date = "23-03-2021";
TemporalAccessor d = DateTimeFormatter.ofPattern("dd-MM-yyyy").parse(date);
String paymentdate = DateTimeFormatter.ofPattern("MM/dd/yyyy").format(d);
System.out.println(paymentdate);
Output :
03/23/2021