title: How to specify UTC timezone for Spring Boot JPA Timestamp
body: <p><strong>Environment</strong></p>
  
  <ul>
  <li>Spring Boot Starter Data JPA 1.4.2</li>
  <li>Eclipselink 2.5.0 </li>
  <li>Postgresql 9.4.1211.jre7</li>
  </ul>
  
  <p><strong>Problem</strong></p>
  
  <p>I am building a Spring Boot microservice that shares a Postgresql database with a different service. The database gets initialized externally (out of our control) and the datetime column type used by the other service is <strong>timestamp without time zone</strong>. Therefore, since I want all dates on the db to have the same type, having that type is a requirement for my JPA entity dates.</p>
  
  <p>The way I map them on my JPA entity objects is as follows:</p>
  
  <pre><code>@Column(name = "some_date", nullable = false)
  private Timestamp someDate;
  </code></pre>
  
  <p>The problem is that when I create a Timestamp as follows: </p>
  
  <pre><code>new java.sql.Timestamp(System.currentTimeMillis())
  </code></pre>
  
  <p>and I look at the database, the timestamp contains my local timezone date time, but I want to store it in UTC. This is because my default Timezone is set to 'Europe/Brussels' and JPA/JDBC converts my <code>java.sql.Timestamp</code> object into my timezone before putting it into the database.</p>
  
  <p><strong>Found not ideal solutions</strong></p>
  
  <ul>
  <li><p><code>TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));</code> has the effect that I want to achieve, but it's not suitable because it is not specific to my service. I.e. it will affect the whole JVM or the current thread plus children.</p></li>
  <li><p>Starting the application with <code>-Duser.timezone=GMT</code> seems to also do the job for a single instance of a running JVM. Therefore, a better solution than the previous one.</p></li>
  </ul>
  
  <p>But is there a way to specify the timezone within the JPA/datasource/spring boot configuration?</p>