Add sample code to get current date in Java 8

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

View File

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