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?

2
  • 1
    You're mixing month and minutes. Month should be using M not m. And hour should be using H for 24 hours. Commented Apr 14, 2013 at 12:29
  • Months start from 00, not 01. Jan = 00, Feb = 01, Dec = 11. Don't expect Apr for 04. Commented Apr 14, 2013 at 13:11

1 Answer 1

5

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

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

Detailed information is on this page.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.