From ba4fb5bf42c062bcd38b51e6e2d4625337894f41 Mon Sep 17 00:00:00 2001 From: sanketmeghani Date: Sun, 18 Sep 2016 17:06:12 +0530 Subject: [PATCH] Add sample code to get current time in Java 8 --- .../com/baeldung/util/GetCurrentTime.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core-java-8/src/main/java/com/baeldung/util/GetCurrentTime.java diff --git a/core-java-8/src/main/java/com/baeldung/util/GetCurrentTime.java b/core-java-8/src/main/java/com/baeldung/util/GetCurrentTime.java new file mode 100644 index 0000000000..39934c94bf --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/util/GetCurrentTime.java @@ -0,0 +1,20 @@ +package com.baeldung.util; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; + +public class GetCurrentTime { + + public static void main(String args[]) { + + LocalTime localTime = LocalTime.now(); + System.out.println("Current time is: " + localTime); + + localTime = LocalTime.now(ZoneId.of("GMT+02:30")); + System.out.println("Current time in GMT +02:30 timezone: " + localTime); + + LocalDateTime localDateTime = LocalDateTime.now(); + System.out.println("Current time is: " + localDateTime.toLocalTime()); + } +}