In this recipe, we will look at using java.time.Instant to represent a point in time, as well as convert that point in time to epoch seconds/milliseconds. The Java epoch is used to refer to the time instant 1970-01-01 to 0:00:00Z and java.time.Instant stores the number of seconds from the Java epoch. A positive value indicates the time is ahead of the epoch and negative indicates the time is behind the epoch. It uses the system clock in UTC to compute the current time instant value.
How to represent epoch time
Getting ready
You need to have JDK supporting new Date/Time APIs and JShell installed to be able to try out the solution provided.