Epoch Time In Java
Chapter:
Date and Time
Last Updated:
27-04-2016 15:23:33 UTC
Program:
/* ............... START ............... */
import java.time.Instant;
public class JavaEpochTime {
public static void main(String[] args) {
Instant instant = Instant.now();
long seconds = instant.getEpochSecond();
System.out.println("Seconds since epoch: " + seconds);
System.out.println("Years since epoch: " + (double) seconds / 31536000);
}
}
/* ............... END ............... */
Output
Seconds since epoch: 1461765449
Years since epoch: 46.35227831684424
Tags
Epoch Time, Java, Date And Time