It's not a coincidence that this question has the same exact title as this one. Same problem, different environment.
My Angular-based application sends the Tomcat server a date taken from Angular UI Calendar Picker in ISO format and UTC time zone, so that if I choose May 1st 2016
in the CEST
time zone it will be Apr 30 22:00 +2
in JSON. And Postgres will save that wrong value too! Mysql, SQL Server and Oracle are not affected by this problem (explanation below)
Here is a step-by-step explanation of the round-trip
- User selects
11/04/1956
indd/MM/yyyy
format - Client sends
"birthDate" : "1956-04-10T22:00:00.000Z"
- Spring MVC, using Jackson, will decode
Tue Apr 10 23:00:00 CET 1956
. Please note that Apr 30 should be in daylight saving already - Hibernate will save that data to Postgres on a column of type
java.util.Date
annotated with@Temporal(DATE)
- Postgres will store
1956-04-10
in that column - Spring requests via Ajax a JSON representation of the entity, and that contains
"birthDate" : "1956-04-10"
in the body
Additional considerations:
- I have already faced and solved the problem in other DBs by setting Tomcat time zone. Not really the smartest solution ever, because imposing
-Duser.timezone
requires exact synchronization with client time zone, which is not possible in an international environment, which ours is not - I mean we are lucky all our customers are from the same location, no matter London Rome or Paris - The issue does happen only when date fields strip the time. I mean if we store a column as datetime to only keep the track of the date, it will always be presented correctly
- I have already read this bug but it provides no helpful information
- Worse, I need this problem solved or worked around due to time constraints. Manually editing DB entries where incorrect is the last stand
I have little experience with Postgres anyway.
Is there any option to force Postgres timezone from JDBC or Hibernate properties? (workaround)
Or what is the correct solution to this kind of issue?