简体   繁体   English

没有时区的时间戳的Hibernate DST日期映射问题

[英]Hibernate DST Date mapping issue for timestamps without time zone

I've a problem with storing java.util/sql.Date in PostgreSQL using hibernate: I'm storing dates as timestamp without time zone type. 我在使用hibernate的PostgreSQL中存储java.util / sql.Date时遇到问题:我将日期存储为时间戳,没有时区类型。 Now, in most cases everything is alright, as I'm mapping it in entities as java.util(sql).Date . 现在,在大多数情况下,一切都很好,因为我将其映射为java.util(sql).Date实体

However, I encountered one problem I don't know how to overcome yet: On March 30th there was a time change ( Daylight Saving Time started). 但是,我遇到了一个尚不知道如何解决的问题:3月30日发生了时间更改( 夏令时开始)。 In my country it meant switching from local 2am to local 3am . 在我国,这意味着从凌晨2点切换到凌晨3点

In my database I have few entries with times between 2 and 3 am, such as 在我的数据库中,我只有几个条目,它们的时间 2点至3点之间 ,例如

"2014-03-30 02:15:55" “ 2014-03-30 02:15:55”

Now, what Java does is it takes this date and displays it as 3:15:55 am, because of the time change. 现在,Java所做的是,由于时间的变化,它会采用这个日期并将其显示为上午3:15:55。 However, I desperately need it to be 02:15:55, exactly how it's stored in the database (basically meaning don't use the +02:00 timezone BEFORE 3am, but use it AFTER ). 但是,我非常需要将其设置为02:15:55,准确地将其存储在数据库中(基本上意味着不要凌晨3点之前使用+02:00时区,而应在之后使用)。 I'm afraid about 26th October as well, that's when the DST ends. 我也担心10月26日,即夏令时结束。

Is this possible using Hibernate and/or Spring? 使用Hibernate和/或Spring是否可能? I'd love a global config for such case. 我喜欢这种情况下的全局配置。

Best, Marcin 最好,Marcin

You need to store dates in UTC timezone to ignore DST. 您需要将日期存储在UTC时区中才能忽略DST。 See this question How to store date/time and timestamps in UTC time zone with JPA and Hibernate for solutions 查看此问题如何使用JPA和Hibernate在UTC时区中存储日期/时间和时间戳以获取解决方案

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

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