title: Using ZonedDateTime with datetimeoffset in SQLServer
body: <p>I have an application that uses a SQLServer database with datetimeoffset columns. Preferably, I would like to use ZonedDateTime as my JPA entity object type like so:</p>
  
  <pre><code>@Column(name = "CreateTimestamp", nullable = false)
  ZonedDateTime createTimestamp;
  </code></pre>
  
  <p>However, the timezone is not being properly saved. No matter what I set the ZoneId to in the ZonedDateTime, the value will always be in GMT in the database.</p>
  
  <p>Looking at <a href="https://docs.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types" rel="noreferrer">Microsoft's JDBC mapping diagram</a>, the recommended class to use is microsoft.sql.DateTimeOffset which is not what I would prefer.</p>
  
  <p>I've explored using a @Converter to map between the two, but having to provide special knowledge like this seems like a red flag that I'm doing something wrong - especially since I need this to work inside of an integration test using H2.</p>
  
  <p>What is the best way to use datetimeoffset and ZonedDateTime in a vendor agnostic way?</p>