Legacy Date
Description
An object of the Date class stores the number of milliseconds elapsed since the epoch, midnight January 1, 1970 UTC. and represents an instant in time.
The Date class default constructor creates a Date object with the current system datetime.
Example
The following code shows how to use Date class.
import java.util.Date;
/* w w w . j a v a2 s . c o m*/
public class Main {
public static void main(String[] args) {
Date currentDate = new Date();
System.out.println("Current date: " + currentDate);
long millis = currentDate.getTime();
System.out.println("Current datetime in millis: " + millis);
}
}
The code above generates the following result.