You want to find today’s date.
The quick and simple way to get today’s date and time is to
Date object with no arguments in the
constructor call, and call its
toString( ) method:
// Date0.java System.out.println(new java.util.Date( ));
However, for reasons just outlined, we want to use a
object. Just use
Calendar.getInstance().getTime( ), which returns a
Date object (even though the name makes it seem
like it should return a
Time value), and print the
Date object, either using its
toString( ) method or a
DateFormat object. You might be tempted to
GregorianCalendar object, using the
no-argument constructor, but if you do this, your program will not
give the correct answer when non-western
subclasses of their own (in some future release of Java). The static
returns a localized
Calendar subclass for the locale you are in. In
North America and Europe it will likely return a
GregorianCalendar, but in other parts of the world
it might (someday) return a different kind of
Do not try to use a
method; the results are truly impressive, but not very interesting.
Sun’s implementation prints all its internal state information;
toString( ), which just prints the class name and
the hashcode. Neither is useful for our purposes.
// Date1,.javaj ...