img
Sample output is shown here:
Mon Jan 01 16:28:16 CST 2007
Milliseconds since Jan. 1, 1970 GMT = 1167690496023
Calendar
The abstract Calendar class provides a set of methods that allows you to convert a time in
milliseconds to a number of useful components. Some examples of the type of information
that can be provided are year, month, day, hour, minute, and second. It is intended that
subclasses of Calendar will provide the specific functionality to interpret time information
according to their own rules. This is one aspect of the Java class library that enables you
to write programs that can operate in international environments. An example of such a
subclass is GregorianCalendar.
Calendar provides no public constructors.
Calendar defines several protected instance variables. areFieldsSet is a boolean that
indicates if the time components have been set. fields is an array of ints that holds the
components of the time. isSet is a boolean array that indicates if a specific time component
has been set. time is a long that holds the current time for this object. isTimeSet is a boolean
that indicates if the current time has been set.
Some commonly used methods defined by Calendar are shown in Table 18-4.
Method
Description
abstract void add(int which, int val)
Adds val to the time or date component specified
by which. To subtract, add a negative value. which
must be one of the fields defined by Calendar, such
as Calendar.HOUR.
boolean after(Object calendarObj)
Returns true if the invoking Calendar object
contains a date that is later than the one specified
by calendarObj. Other wise, it returns false.
boolean before(Object calendarObj)
Returns true if the invoking Calendar object contains
a date that is earlier than the one specified by
calendarObj. Other wise, it returns false.
final void clear( )
Zeros all time components in the invoking object.
final void clear(int which)
Zeros the time component specified by which in
the invoking object.
Object clone( )
Returns a duplicate of the invoking object.
boolean equals(Object calendarObj)
Returns true if the invoking Calendar object
contains a date that is equal to the one specified
by calendarObj. Other wise, it returns false.
TABLE 18-4
Commonly Used Methods Defined by Calendar
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home