Wer*_*001 4 mysql timezone timestamp jdbc utc
我想将时间戳保存到数据库,而不是由jdbc驱动程序转换为本地时区.目前只有MySQL和PostgreSQL对我很重要,但如果有一个独立于数据库的解决方案,我将不胜感激.
例:
// i want that to be saved as 1970-01-01 00:00:00
TimeStamp ts = new java.sql.Timestamp(0);
// gets transformed to local time by jdbc driver (in my case to 1970-01-01 01:00:00)
st.setTimestamp(0, new java.sql.Timestamp(0));
// only works using postgres (mysql connector seems to ignore the calendar)
// postgres => 1970-01-01 00:00:00
// mysql => 1970-01-01 01:00:0
Calendar calutc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
st.setTimestamp(0, new java.sql.Timestamp(0), utccal);
Run Code Online (Sandbox Code Playgroud)
我已经尝试计算一个时间戳值,该值被转换为正确的值(例如-3600000 => 1970-01-01 00:00:00在我的时区)但这对于当天日期的postgres不起作用节约时间的变化.
Wer*_*001 12
我找到了解决方案.MySQL在他们的JDBC连接器中有一个错误,忽略了为setTimestamp/getTimestamp提供的Calendar对象.他们修复了连接器版本5.1.5中的错误,但旧的(不正确的)行为仍然是默认行为.要使用正确的代码,您必须将参数"useLegacyDatetimeCode = false"传递给连接器URL.
更多信息:http: //bugs.mysql.com/bug.php?id = 15604
| 归档时间: |
|
| 查看次数: |
7232 次 |
| 最近记录: |