Message-ID: From: "michalkoza (@michalkoza)" To: "pgjdbc/pgjdbc" Date: Wed, 07 Aug 2024 21:58:38 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #1325: Additional jsr 310 support In-Reply-To: References: List-Id: X-GitHub-Author-Login: michalkoza X-GitHub-Comment-Id: 2274419867 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 1325 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/1325#issuecomment-2274419867 Content-Type: text/plain; charset=utf-8 @marschall Conversion from java.sql.Timestamp -> Instant is independent of time zone. Check this code: ```java TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); LocalDateTime localDateTime = LocalDateTime.of(2018, 11, 16, 18, 2); Timestamp timestamp = Timestamp.valueOf(localDateTime); Instant instant1 = timestamp.toInstant(); System.out.println("timestamp in LA zone " + timestamp); System.out.println("instant1 in LA zone " + instant1); TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); Instant instant2 = timestamp.toInstant(); System.out.println("timestamp in NY zone " + timestamp); System.out.println("instant1 in NY zone " + instant1); System.out.println("instant2 in NY zone " + instant2); long epochMilli1 = instant1.toEpochMilli(); long epochMilli2 = instant2.toEpochMilli(); System.out.printf("epochMilli1: %d%n", epochMilli1); System.out.printf("epochMilli2: %d%n", epochMilli2); System.out.println("same instant: " + instant1.equals(instant2)); ``` If you have a fixed timestamp, you can change time zones and convert it to Instant many times, always getting the same result. Observe also that even though the `timestamp` is never changed it is displayed differently depending on time zone, but it keeps the same value. In your example the difference comes from the fact that 18:02 in LA is different moment in time than 18:02 in NY. It would be surprising if your Instants and Timestamps would be equal. `Instant` is a moment in time in UTC. The same goes for `TIMESTAMP` type in PostgreSQL. They are both timezone-agnostic. So I struggle to understand why would you not want to store Instant as TIMESTAMP rather than TIMESTAMPTZ