Finding Today s Date


Finding Today's Date

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.




JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net