String (dd-MM-yyyy HH:mm) to Date (yyyy-MM-dd HH:mm) | Java

Posted by Panther24 on Stack Overflow See other posts from Stack Overflow or by Panther24
Published on 2010-12-22T17:38:38Z Indexed on 2010/12/22 17:54 UTC
Read the original article Hit count: 210

Filed under:
|

I have a string in "dd-MM-yyyy HH:mm" and need to convert it to a date object in the format "yyyy-MM-dd HH:mm".

Below is the code I'm using to convert

oldScheduledDate = "16-05-2011 02:00:00";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date oldDate = (Date)formatter.parse(oldScheduledDate);

Now when I print oldDate, i get

Sat Nov 01 02:00:00 GMT 21, which is completely wrong, what am I doing wrong here?

© Stack Overflow or respective owner

Related posts about java

Related posts about conversion