If you're new to Java, but have used other programming languages in the
past, you'll likely think that simply printing today's date in an understandable
format is overly complex. I agree.
But, there is good reason. The way we read today's date is not the
same way it is read in many other contries or planets. (you still awake
back there?) Thus, Java separates the keeping of time from the presenting
of time.
class GregorianCalendar can do many things that Date simply
cannot. You will probably find you will use GregorianCalendar
quite often when you want to use a Date.
That does not mean class Date is completely useless. It does store
the instance in time, and, since you can compare one date to another reguardless
of presentation, you can use Date.before(Date date) and Date.after(Date
date) methods to compare one Date to another.
With class Date, there are only two constructors you can use (that are
not deprecated).
Date() instantiates a Date object to the current date and time.
Date(long milliseconds) instantiates a Date object to the given number
of milliseconds since January 1, 1970.
But, GregorianCalendar has constructors that are particularly useful.
GregorianCalendar() constructs a new GregorianCalendar with the current
date and time.
GregorianCalendar(2002, 0, 16) constructs a GregorianCalendar with the
date January 16, 2002.
Why the 0? This is confusing. Months start counting at 0, not
1, so January is month 0. Why do months start at 0, but days and
years start at their natural start? Beats me.
So, you can use the constants of the Calendar class, which is the class
that GregorianCalendar extends. GregorianCalendar(2002, Calendar.JANUARY,
16)
You can set the time as well: GregorianCalendar(2002, Calendar.JANUARY,
16, 14, 30, 00) sets the GregorianCalendar to January 16, 2002, 2:30:00
PM.