I am trying following piece of code:
SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/YY");
Date d=formatter.parse("05/12/15");
System.out.println(formatter.format(d));
Expected output: 05/12/15
Actual output: 12/362/15
I am trying following piece of code:
SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/YY");
Date d=formatter.parse("05/12/15");
System.out.println(formatter.format(d));
Expected output: 05/12/15
Actual output: 12/362/15
The used pattern is wrong. As stated here
DD
returns the "day in year" whereas you needdd
for the "day in month". Hence, the correct code is: