Java Reference
In-Depth Information
A java.text.SimpleDateFormat class
that
formats
and
parses
Gregorian dates and times
For example, the following code creates a GregorianCalendar object rep-
resenting midnight (00:00:00), October 26, 1972, in the local time
zone, then prints its value:
Calendar cal =
new GregorianCalendar(1972, Calendar.OCTOBER, 26);
System.out.println(cal.getTime());
The method getTime returns a Date object for the calendar object's time,
which was set by converting a year, month, and date into a millisecond-
measured long . The output would be something like this (depending on
your local time zone of course):
Thu Oct 26 00:00:00 GMT+10:00 1972
You can also work directly with the millisecond time value by using
getTimeInMillis and setTimeInMillis . These are equivalent to working
with a Date object; for example, getTimeInMillis is equivalent to invoking
getTime().getTime() .
The abstract Calendar class provides a large set of constants that are
useful in many calendars, such as Calendar.AM and Calendar.PM for calen-
dars that use 12-hour clocks. Some constants are useful only for cer-
tain calendars, but no calendar class is required to use such constants.
In particular, the month names in Calendar (such as Calendar.JUNE ) are
names for the various month numbers (such as 5month numbers start
at 0 ), with a special month UNDECIMBER for the thirteenth month that many
calendars have. But no calendar is required to use these constants.
Each Calendar object represents a particular moment in time on that cal-
endar. The Calendar class provides only constructors that create an ob-
 
Search WWH ::




Custom Search