title: Why is Java 8 Instant.now() showing the wrong UTC on my local server?
body: <p>Java8 <code>Instant.now()</code> gives the current time already formatted in UTC. I created a simple sandbox test on <a href="https://www.compilejava.net/" rel="nofollow noreferrer">CompileJava.net</a> to verify my intented results:</p>
  
  <pre><code>Timestamp createdDateUtc = Timestamp.from(Instant.now());
  System.out.println(createdDateUtc);
  
  LocalDateTime databaseUtcLocal = createdDateUtc.toLocalDateTime();
  ZonedDateTime databaseUtcZoned = databaseUtcLocal.atZone(ZoneId.of("UTC"));
  ZonedDateTime userTimezoneTime = databaseUtcZoned.withZoneSameInstant(ZoneId.of("Asia/Qatar")); 
  System.out.println(userTimezoneTime.format(DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a")));
  </code></pre>
  
  <p><em>Note: it is currently 11:16 AM UTC on 12/01/2018.</em></p>
  
  <p>When I run this code on the online compiler, I get the output:</p>
  
  <pre><code>2018-12-01 11:17:43.637
  12/01/2018 02:17:43 PM
  </code></pre>
  
  <p>But when I run this code on my local JBOSS server, I get this output instead:</p>
  
  <pre><code>2018-12-01 03:18:07.464
  12/01/2018 06:18:07 AM
  </code></pre>
  
  <p>What could be going wrong here? Is my server UTC clock incorrect? My local server's physical location is in California. While that shouldn't matter, it does seem odd that when I'm trying to display the UTC time using <code>Instant.now()</code> I get Pacific Time instead. </p>
  
  <p>Any help much appreciated!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As pointed out by the accepted answer, the issue was my <code>Timestamp.from()</code> method:</p>
  
  <pre><code>System.out.println(Instant.now());
  System.out.println(Timestamp.from(Instant.now()));
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>2018-12-01T11:48:33.153Z
  2018-12-01 03:48:33.171
  </code></pre>
  
  <p>So now my issue has changed. If you have a similar issue, I found my answer on this Stack Overflow <a href="https://stackoverflow.com/questions/43837323/how-do-i-make-java-sql-timestamp-utc-time">here</a>. Instead of <code>Timestamp.from(Instant.now())</code> I used this ugly mess: </p>
  
  <pre><code>Timestamp.valueOf(ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime())
  </code></pre>