Try this:
new SimpleDateFormat("MM/dd/yyyy")
MM
is “month” (notmm
)dd
is “day” (notDD
)
It’s all in the javadoc for SimpleDateFormat
FYI, the reason your format is still a valid date format is that:
mm
is “minutes”DD
is “day in year”
Also, you don’t need the cast to Date
… it already is a Date
(or it explodes):
public static void main(String[] args) throws ParseException {
System.out.println(new SimpleDateFormat("MM/dd/yyyy").parse("08/16/2011"));
}
Output:
Tue Aug 16 00:00:00 EST 2011
Voila!