【发布时间】:2016-12-09 06:42:47
【问题描述】:
我在流中以字符串形式获取时间戳,它们的格式为 "2016-12-08 05:44:48 <timezone like IST, UTC>" 和 "2016-12-08 05:44:48 <timezone like +0000>"
我想把字符串转换成java.sql.Timestamp所以我写了一个函数如下
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());
}
当我跑步时
Timestamp t = convertToTimestamp("2016-12-08 05:44:48 UTC");
System.out.println(t);
输出为2016-12-08 11:14:48.0
它会自动转换为 IST(可能是我的 JVM 默认值)。 如何进行更改以使输出时间不更改为IST并且与输入时间相同?
【问题讨论】: