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
On
The used pattern is wrong. As stated here DD returns the "day in year" whereas you need dd for the "day in month". Hence, the correct code is:
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
You are using uppercase D which is the day of the year. Use lower case d for day of the month. The year y should be lower case as well i.e
"MM/dd/yy".See SimpleDateFormat documentation.