2

I'm trying to parse a string to date object in Java.
My string is: String date = 2013-04-13 21:00:00; The code is:

    String myFormatString = "yyyy-mm-dd hh:mm:ss";
    Date date1 = new SimpleDateFormat(myFormatString, Locale.ENGLISH).parse(date);
    System.out.println(date1);

I'm expecting the output to be: Sun Apr 13 21:00:00 GMT+00:00 2013
but what I get is: Sun Jan 13 21:00:00 GMT+00:00 2013

Can you see why?

Sharon Haim Pour
  • 6,595
  • 12
  • 42
  • 64
  • 1
    You're mixing month and minutes. Month should be using M not m. And hour should be using H for 24 hours. – maba Apr 14 '13 at 12:29
  • Months start from 00, not 01. `Jan = 00, Feb = 01, Dec = 11`. Don't expect Apr for 04. – smttsp Apr 14 '13 at 13:11

1 Answers1

5

Months are represented by "M", "m" is for minutes.

String myFormatString = "yyyy-MM-dd hh:mm:ss";

Detailed information is on this page.

Cebence
  • 2,406
  • 2
  • 19
  • 20