SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
Date date = dateFormat.parse("11/04/2011");
System.out.println(date);
System.out.println(dateFormat.format(date));
Tue Jan 04 00:11:00 IST 2011
11/04/2011
When output the date object it shows as january instead of november. But when format the same date object it shows november correctly.
By making MM/dd/yyyy it both shows the correct result. But Shouldnt the mm/dd/yyyy throws an Unparseable date exception if mm/dd/yyyy is fishy?
A common error:
mmis the pattern for minutes. You want to useMMto parse/print the month. UseMM/dd/yyyyinstead ofmm/dd/yyyy.Since you parse the value
11into the minute-part of the date and then print the minute-part of the date in the first place, the result ofdateFormat.format(date)looks correct.