get current java zoned date time code example

Example 1: How to get current date and time in java

// get current date and time in java using LocalDate.now() method
import java.time.LocalDate;
public class UsingLocalDate
{
   public static void main(String[] args)
   {
      System.out.println(LocalDate.now());
   }
}

Example 2: How to get current date and time in java

// how to get current date and time in java 
// using Date class and System.currentTimeMillis() method
import java.util.Date;
public class UsingDateClass
{
   public static void main(String[] args) 
   {
      Date dt = new Date();
      System.out.println(dt);
      long milliSeconds = System.currentTimeMillis();  
      Date date = new Date(milliSeconds);
      System.out.println(date); 
   }
}

Tags:

Java Example