From 1b4714c214236ae4d7a8a25bdfce3feff74e0932 Mon Sep 17 00:00:00 2001 From: sanketmeghani Date: Sun, 18 Sep 2016 17:06:34 +0530 Subject: [PATCH] Add sample code to get current timestamp in Java 8 --- .../com/baeldung/util/GetCurrentTimestamp.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 core-java-8/src/main/java/com/baeldung/util/GetCurrentTimestamp.java diff --git a/core-java-8/src/main/java/com/baeldung/util/GetCurrentTimestamp.java b/core-java-8/src/main/java/com/baeldung/util/GetCurrentTimestamp.java new file mode 100644 index 0000000000..2387a721cf --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/util/GetCurrentTimestamp.java @@ -0,0 +1,14 @@ +package com.baeldung.util; + +import java.time.Instant; + +public class GetCurrentTimestamp { + + public static void main(String args[]) { + + Instant instant = Instant.now(); + System.out.println("Current timestamp is: " + instant.toEpochMilli()); + + System.out.println("Number of seconds: " + instant.getEpochSecond()); + } +}