当我插入new Date()
对象使用jdbcTemplate
到Oracle数据库,我可以看到jdbc驱动程序或Spring jdbcTemplate插入Date
使用本地 JVM 偏移量。
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date timeZoneDate = sdf.parse("09-SEP-1987");
例如,当我插入在 GMT 中创建的日期对象时,如果 JVM 时区是美国,则会在 Oracle 数据库中插入 08-SEP-1987。
Neither java.util.Date
也不是甲骨文Date
存储时区信息。在您的情况下,Jdbc 驱动程序使用 JVM 时区转换您的日期。您可以使用以下选项之一:
- 如果您使用的是PreparedStatement,则可以使用
setDate(int
parameterIndex, Date x, Calendar cal)
指定方法Calendar
在 UTC 时区。
- 春季用
jdbcTemplate
而不是插入Date
对象,插入Calendar
with UTC
时区
-
TimeZone.setDefault(TimeZone.getTimeZone("GMT"))
可以在 JVM lvl 上设置
- Use
-Duser.timezone=GMT
在 JVM 启动时
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)