I get timestamps as a String in a stream and they are of the format "2016-12-08 05:44:48 <timezone like IST, UTC>"
and "2016-12-08 05:44:48 <timezone like +0000>"
I want to convert the string to java.sql.Timestamp so I wrote a function as follows
private static Timestamp convertToTimestamp(String s) throws ParseException{
String dateFormat = new String("yyyy-MM-dd hh:mm:ss z");
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date d = sdf.parse(s);
return new Timestamp(d.getTime());
}
When I run
Timestamp t = convertToTimestamp("2016-12-08 05:44:48 UTC");
System.out.println(t);
The output is 2016-12-08 11:14:48.0
It is automatically converting into IST (Probably my JVM default). How to make the change so that the output time not changed to IST and is same as input?