Q:

String to Date not formatted correctly

I am trying to do a simple String to Date conversion in Java. I am skimming the date off some logs and need to convert it to a date to do some processing. A date coming through will look like this:
2012-09-07 19:53:33

In my code when I try to convert this into a Date object I get a completely different date. My code looks like this:
String taskStart = "2012-09-07 19:53:33";  
String dateFormat = "yyyy-MM-dd hh:MM:ss";
SimpleDateFormat dateFormat=new SimpleDateFormat(format);
Date taskStartDate = dateFormat.parse(taskStart); 

The output I get is this:
Sat May 07 19:00:27 PDT 2016

How can I just simply convert my original date to the correct format??

A:

You've specified MM (month in year) twice. The m's for "minute" must be lowercase.
If you're taking 24-hour based times, you need to specify HH in order to capture hours that are specified in the range of 0-23, as opposed to hh which expects AM/PM hours (hours in the range of 1-12 with an AM/PM specifier as part of the time string)
Finally, your example code doesn't define the format variable that you're passing into the constructor for your SimpleDateFormat object. In fact, you're using the variable name dateFormat twice and not defining the format variable at all - at least not according to the code that you included in the question.

So, your proper format string, I believe, should be...
"yyyy-MM-dd HH:mm:ss"

...and the full, proper code example would be:
String taskStart = "2012-09-07 19:53:33";  
String format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat dateFormat=new SimpleDateFormat(format);
Date taskStartDate = dateFormat.parse(taskStart); 

A:

According to the documentation for SimpleDateFormat you should use an upper case "H" for hours of the format 0-23. Also, minutes are represented by a lowercase "m".
String dateFormat = "yyyy-MM-dd HH:mm:ss";

