title: How to convert LocalDateTime to com.google.protobuf.Timestamp?
body: <p>I have an instance of LocalDateTime, which I get from the repository layer, and I need to convert it to a Timestamp (Protocol Buffer) instance.</p>
  
  <p>I have used to following approach for the conversion:</p>
  
  <pre><code>LocalDateTime localDateTime = LocalDateTime.now();//this can be any date
  
  Instant instant = localDateTime.toInstant(ZoneOffset.UTC);
  
  Timestamp timestamp = Timestamp.newBuilder()
                              .setSeconds(instant.getEpochSecond())
                              .setNanos(instant.getNano())
                              .build();
  </code></pre>
  
  <p>Is the ZoneOffset used here, to convert localDateTime to an instance of Instant, correct?</p>
  
  <p>I have used the UTC offset because the comment on the "seconds" attribute in the Timestamp class says the following:</p>
  
  <blockquote>
    <p>Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
    Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive</p>
  </blockquote>
  
  <p>Have I used the correct ZoneOffset and is my conversion approach correct?</p>