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