Add sample code to get current time in Java 8

This commit is contained in:
sanketmeghani 2016-09-18 17:06:12 +05:30
parent ef54cd43cb
commit ba4fb5bf42
1 changed files with 20 additions and 0 deletions

View File

@ -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());
}
}