Date

Java provides the Date class available in java.util package, this class encapsulates the current date and time.

This is very easy to get current date and time in Java. You can use a simple Date object with toString() method to print current date and time as follows:

import java.util.Date;
 
public class DateDemo {
   public static void main(String args[]) {
       // Instantiate a Date object
       Date date = new Date();
       
       // display time and date using toString()
       System.out.println(date.toString());
   }
}

This would produce the following result:

on May 04 09:51:52 CDT 2009