title: How to convert an Epoch timestamp into an object of type java.time.Instant Accurately in Java?
body: <p>I have a Spring Boot JPA Application that interacts with a 3rd party API.
  The response payload of the API has a key </p>
  
  <p>"created_at": 1591988071</p>
  
  <p>I need to parse this field into java.time.Instant so that I can do some comparisons with the value I have in the Database.
  I have learned that I can use the below mentioned piece of code.</p>
  
  <pre><code>    Instant instant = Instant.ofEpochSecond(1591988071);
  </code></pre>
  
  <p>Output :</p>
  
  <pre><code>    2020-06-12T18:54:31Z
  </code></pre>
  
  <p><strong>But to be honest, this output is off by a couple of hours.</strong></p>
  
  <p>I found another approach, wherein if I use</p>
  
  <pre><code>    String dateAsText = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
              .format(new Date(1591988071 * 1000L));
      System.out.println(dateAsText);
  </code></pre>
  
  <p>I get the desired output but in String format.</p>
  
  <pre><code>    2020-06-13 00:24:31
  </code></pre>
  
  <p><strong>Can someone tell me how to obtain the above String output but converted into type java.time.Instant ?</strong></p>