SimpleDateFormat ignoring month when parsing

manu picture manu · Jun 16, 2010 · Viewed 52.6k times · Source

The following code is giving me the parsed date as "Wed Jan 13 00:00:00 EST 2010" instead of "Wed Jun 13 00:00:00 EST 2010". Any ideas much appreciated.

    SimpleDateFormat sf = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss");

    String str = "2010-06-13T00:00:00";

    Date date = sf.parse(str);

    System.out.println(" Date " + date.toString());

Answer

Mark Byers picture Mark Byers · Jun 16, 2010

Try:

"yyyy-MM-dd'T'HH:mm:ss"

MM means month. mm means minutes. See the documentation for SimpleDateFormat for more details of the supported date and time patterns.