I am converting Date from String type Date to Date type Date,using SimpleDateFormat but the
resulting date I am getting is getting changed.can anyone tell me why its changing
Also what should i use to get the correct Date type date from String and not the changed one as I am getting here.
Date d = null;
String startTime="2012-03-17 16:00:00 PM";
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
try {
d= sdf.parse(startTime);
} catch (ParseException e) {}
System.out.println("DD="+d) //printing Sun Mar 18 04:00:00 IST 2012 ? why this
//Date enterd was 17 Mar 2012
It is ambigous if you combine a 24h clock and an AM/PM marker. In your case you should either use “HH” (capital H) to parse the hour field in the range 0-23 and ignore the AM/PM suffix or use a 12h-clock with appropriate AM/PM suffix (in your case “04:00:00 PM”).