Date today = new java.util.Date(); System.out.println("Today's Date is " + today.toString());
The Date object in the java.util package is a class that you should be familiar with if your program deals with dates and times, as it is commonly used. Getting the current time and date is a very simple task. When you create an instance of the Date object, it is initialized with the current time and date.
An alternative method to getting the current date and time is to use the Calendar class. The following code will also get you the current date and time:
Calendar cal = Calendar.getInstance();
This will produce a Calendar object, cal, initialized with the current date and time.