I have a string in the pattern yyyy-MM-dd hh:mm a and i can get the time zone object separately in which the above string represents the date.
I want to convert this
Undoubtedly, the format which is generally used will be of a form 2014-10-05T15:23:01Z (TZ)
For that one has to use this code
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String dateInString = "2014-10-05T15:23:01Z";
try {
Date date = formatter.parse(dateInString.replaceAll("Z$", "+0000"));
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
Its output will be Sun Oct 05 20:53:01 IST 2014
However, I am not sure why we had to replaceAll "Z" if you do not add replaceAll the program will fail.