title: How to convert java.sql.Timestamp to java.time.OffsetDateTime?
body: <p>I'm working on a Scala project and I need to map <code>OffsetDateTime</code> type to SQL <code>Timestamp</code> type. In DB I would like to have UTC times.</p>
  
  <p>The conversion from <code>OffsetDateTime</code> to <code>Timestamp</code> is straightforward (hint from <a href="https://stackoverflow.com/questions/30651210/convert-offsetdatetime-to-utc-timestamp">this question</a>) and it works as expected:</p>
  
  <pre><code>import java.time._
  import java.sql.Timestamp
  val ofsdatetime = OffsetDateTime.now()
  // ofsdatetime: java.time.OffsetDateTime = 2017-04-04T21:46:33.567+02:00
  
  val tstamp = Timestamp.valueOf(ofsdatetime.atZoneSameInstant(ZoneOffset.UTC).toLocalDateTime())
  // tstamp: java.sql.Timestamp = 2017-04-04 19:46:33.567
  </code></pre>
  
  <p>As you can see, timezone is removed and the Timestamp is two hours back in time (UTC), great!</p>
  
  <p>Converting back <code>Timestamp</code> to <code>OffsetDateTime</code> <strong>isn't working as expected</strong>:</p>
  
  <pre><code>OffsetDateTime.ofInstant(Instant.ofEpochMilli(tstamp.getTime), ZoneId.systemDefault())
  
  // java.time.OffsetDateTime = 2017-04-04T19:46:33.567+02:00
  </code></pre>
  
  <p>Timezone has been added to the newly created <code>OffsetDateTime</code>, but the time is not correct (it's still UTC, I need that it is adapted to the actual timezone).</p>
  
  <p>Why? What am I doing wrong?</p>