I am really confused with the SimpleDateFormat object. Here is the code :
SimpleDateFormat formatter = new SimpleDateFormat("DDHHmm MMM yy", Locale.ENGLISH);
String dateString = "312230 MAR 10";
try
{
Date date = (Date)formatter.parse(dateString);
System.out.println("Original string: " + dateString);
System.out.println("Parsed date : " + date.toString());
}
catch (ParseException e)
{
System.out.println("ERROR: could not parse date in string \"" +
dateString + "\"");
}
and this is the output :
Original string: 312230 MAR 10
Parsed date : Sun Jan 31 22:30:00 EST 2010
I really expected the output to be
Parsed date : Wed Mar 31 22:30:00 EST 2010
Can someone please point out what I am doing wrong? It would be deeply appreciated. I am using java 1.6_27.
Change the simpleDateFormat pattern by “ddHHmm MMM yy” return the expected output
DD on uppercase means day of year. In your example day 31 is in January, how your output, and not in March