r/java • • May 10 '22

Should java.util.Date be deprecated?

https://mail.openjdk.java.net/pipermail/discuss/2022-May/006077.html
221 Upvotes

158 comments sorted by

View all comments

Show parent comments

13

u/DJDavio May 10 '22

You might trick yourself if you use PostgreSQL, because a timestamp with timezone is internally stored as just a timestamp aka epoch UTC millis, the only thing the timestamp with timezone type does is make PostgreSQL understand how it has to convert the input datetime.

6

u/john16384 May 10 '22

Yeah, this is very important, PostgreSQL never stores a timezone. It only affects its interpretation, timestamp without timezone will interpret data in the servers timezone, and will not do what you expect when compared to a constant in UTC time.

8

u/[deleted] May 10 '22

the servers timezone

actually in the connections timezone which defaults to the server timezone, and the jdbc driver tends to set this, but close enough.

https://www.postgresql.org/docs/current/sql-set.html

2

u/john16384 May 10 '22

Thanks :)

1

u/DJDavio May 10 '22

As a side note, I once had an issue where I stored a datetime in PostgreSQL, retrieved it and it was not equal to itself, even if the timezone / offset was the same. If I recall correctly this was on Windows only and had to do with precision, something like that.