简体   繁体   中英

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. 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().

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?

I have considered AM/PM conversions, timezone issues and checked server times, but all seems ok.

Apologies if this is simple but I am a bit lost!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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