Skip to content
Advertisement

How to initialize Google protocol buffers Timestamp in Java?

Google protocol buffers (3.0.0-beta2) offers the well-known type Timestamp.

The documentation describes the initialization in Java using System.currentTimeMillis() as following:

JavaScript

Is there an alternative way in the recent Java 8?

Advertisement

Answer

Starting with Java 8, there is the new Date/Time-API which makes this more appealing to the reader using java.time.Instant

JavaScript

The result should be the same concerning precision.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement