pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: marschall (@marschall) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #1325: Additional jsr 310 support
Date: Fri, 16 Nov 2018 21:56:17 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

> I am not sure I agree. What I see is that LocalDateTime -> Timestamp conversion depends on the JVM default time zone.

It's the same with String -> Timestamp conversion which like LocalDateTime calls the deprecated constructor, see code below. To get from a date time / SQL TIMESTAMP to an instant / point in time / unix timestamp you need to have a time zone. For java.sql.Timestamp this is the JVM default time zone.

```java
String localDateTime = "2018-11-16 18:02:00";

TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
Instant instant1 = Timestamp.valueOf(localDateTime).toInstant();
long epochMilli1 = instant1.toEpochMilli();

TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"));
Instant instant2 = Timestamp.valueOf(localDateTime).toInstant();
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));
```

view thread (25+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #1325: Additional jsr 310 support
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox