I have a date that is in the MM/dd/yy format. I get it from an XML file. Let’s say, for example, it’s 10/03/11.
I execute the following code on it:
try {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("dateStr: " + dateStr);
date = sdf.parse(dateStr);
System.out.println("dateStr After: " + sdf.format(date));
} catch(Exception e) {
System.out.println("Error when formatting date");
}
The output is:
dateStr: 10/03/11 dateStr After: 10/03/0011
I can not seem to get it to be 10/03/2011. Any ideas why?
When the date you are parsing has year with two chars, your
simpleDateFormattershould alsoyyonly.EDIT: