目前,我正在根据sysdate存储时间戳,但是我想以UTC格式保存时间戳。PFB我的实体类中的代码段。
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATE_DT")
private Date createDt = new Date();
如何以UTC格式存储时间戳。
只需将JDBC选项更改为JDBC连接URL:
这些是您需要更改的参数:
useTimezone = true
serverTimezone = UTC
例子:
<bean id="HB_SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<!-- Connection parameters -->
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:mysql://hostname/databaseName?useTimezone=true&serverTimezone=UTC</prop>
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句