I am trying to create a Date object from an input String. The code snippet that I have written is :
inputs are like : effDate = "03/09/2012" and ExpiryDate = "08/31/2012"
System.out.println("eff Date: " + effDate);
SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/yyyy");
Date date = formatter.parse(effDate);
System.out.println("Effective Date = " + formatter.format(date));
The output I get is :
eff Date: 03/09/2012
Effective Date = 01/09/2012
The same happens for the other input as well. like
exp date: 08/31/2012
Expiry Date = 01/31/2012
Does anyone know the reason why its changing the month value from anything(03/08) to 01 ??
Info: I am using jdk1.6 with Eclipse. And running this sample program through JUNIT 4.
new SimpleDateFormat("MM/DD/yyyy");should benew SimpleDateFormat("MM/dd/yyyy");(ddinstead ofDD)DD= Day in yeardd= Day in month