I'm processing a list of dates from an input file, and I need to convert each from String to Date. Examples of the format:
9/2/2013 7:34:17 PM
1/13/2011 10:47:36 AM
Each time a line is read, the date is stored in the String variable dateAsString
. Here's what I've got:
DateFormat format = new SimpleDateFormat("MM/dd/YYYY hh:mm:ss a");
Date myDate = format.parse(dateAsString);
System.out.println(myDate.toString());
The output is incorrect:
9/2/2013 7:34:17 PM becomes Sun Dec 30 19:34:17 EST 2012
1/13/2011 10:47:36 AM becomes Sun Dec 26 10:47:36 EST 2010
It seems pretty straightforward, so I'm confused. What am I doing wrong?