I have done following code:
String str = "2013-01-17 11:26";
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:MM");
Date date = dateFormat.parse(str);
System.out.println("str :"+str);
System.out.println("Date :"+date);
Output
str :21-01-2013 11:26
Date :Sat Feb 21 11:01:00 IST 2015
But something is wrong. I expect out as same as string date. i.e. Thu Jan 21 11:26:00 IST 2013
You are using the wrong format.
MM
is formonth
, andmm
is forminutes
, and forhours
useHH
. SeeSimpleDateFormat
for various other formats.Change your format to: -
Just Using of DateFormat Class:
The following code should work well: