简体   繁体   English

为什么JPA似乎要提前12小时保留java.util.Date()

[英]Why does JPA seem to be persisting java.util.Date() 12 hours in advance

There are several variations of this question, but I am struggling to discover a solution to my problem. 这个问题有几种变体,但是我正在努力寻找解决问题的方法。

I have a JPA, Eclipselink & MySQL based application. 我有一个基于JPA,Eclipselink和MySQL的应用程序。 When a record is added or updated in a specific table an "Updated" date field is set to now by using new java.util.Date(). 在特定表中添加或更新记录时,通过使用新的java.util.Date()将“更新”日期字段设置为现在。

This is the field on my entity class: 这是我的实体类上的字段:

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "Updated", unique = false, nullable = true)
private Date updated;

It is set simply like this: 设置就像这样:

record.setUpdated(new Date());

For some reason the dates set in the database always seems to be 12 hours ahead of now? 由于某种原因,数据库中设置的日期似乎总是比现在早12小时?

I have considered AM/PM conversions, timezone issues and checked server times, but all seems ok. 我已经考虑过AM / PM转换,时区问题和检查服务器时间,但一切似乎都还可以。

Apologies if this is simple but I am a bit lost! 抱歉,这很简单,但我有点迷路!

检查是否在服务器的jvm选项中设置了-Duser.timezone。并检查其值(如果已设置)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM