【问题标题】:Hibernate: @Temporal with different timezone on server and mysqlHibernate:@Temporal 在服务器和 mysql 上具有不同的时区
【发布时间】:2014-09-11 08:40:27
【问题描述】:

我有一个简单的问题:

拥有这样的实体

@Entity
public class Entity {
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Temporal(TemporalType.TIMESTAMP)
    private Date created = new Date();
}

如果我使用具有 GMT+4 时区的服务器保存一个,使用 UTC 数据库服务器

Entity entity = new Entity();
entityDao.save(entity);

真正得救的是什么? Hibernate 保存时是否将 GMT+4 转换为 UTC?

【问题讨论】:

标签: java hibernate date utc


【解决方案1】:

好的,简单的方法是在UTC中使用mysql:

/etc/mysql/my.cnf

[mysqld]
default-time-zone = '+00:00'

并为tomcat设置JAVA_OPTS:-Duser.timezone=GMT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    相关资源
    最近更新 更多