I\'ve the following code:
SimpleDateFormat format = new SimpleDateFormat(\"EEE MMM dd HH:mm:ss z yyyy\");
String s2 = \"Mon Oct 19 19:52:21 IST 2015\";
Using IST
is dangerous as it could stand for Indian or Israel ST.
Assuming you meant Indian ST, try this:
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
format.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
String s2 = "Mon Oct 19 19:52:21 IST 2015";
System.out.println(format.parse(s2));
Also, follow suggestion from @Meno's answer
The code expression
System.out.println(format.parse(s2));
always prints your instant/moment (an object of type java.util.Date
) in your system timezone which is apparently PDT. You implicitly apply the method toString()
on java.util.Date
. Use a dedicated formatter like SimpleDateFormat
and set the timezone on this formatter to achieve the desired result.
Finally you need two formatters, one for parsing and one for printing.