In Java we have Date class available in java.util package which encapsulates the current date and time.
The Date class have two constructors mentioned below:
1 Date( )
This constructor initializes the object with the current date and time. This doesn’t require any argument.
2 Date(long millisec)
We need to provide an argument to this constructor that equals the number of milliseconds that have elapsed since midnight, January 1, 1970
Below is a program to get current date and time:
It is very easy to get current date and time in Java. We need to create Date object with toString() method to print current date and time as follows:
on February 03 10:01:47 CDT 2016