I am doing simple String to date conversion in java, Only one thing i have to take care conversion should be in GMT. I am able to convert my String in GMT. But when i tried to convert that date into timestamp i got different value (Seems value is based on my local timezone).
public static void timeFun(String str) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
String dateInString = "2015-07-10T09:54:31.000-04:00";
Date date = formatter.parse(dateInString);
SimpleDateFormat sdfAmerica = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
TimeZone tz = TimeZone.getTimeZone("GMT");
sdfAmerica.setTimeZone(tz);
String convertedDate = sdfAmerica.format(date); // Convert to String
// first
Date dateInGMT = sdfAmerica.parse(convertedDate);
System.out.println(convertedDate); // Output = 2015-07-10T13:54:31.000Z (Right)
Timestamp timestamp = new java.sql.Timestamp(dateInGMT.getTime());
System.out.println(timestamp); // Output = 2015-07-10 19:24:31.0 (Wrong)
}