Thursday 14 March 2013

java.util Calendar


java.util
Calendar

Declaration
public abstract class Calendar
java.lang.Object
|
+--java.util.Calendar
Description
Calendar is an abstract base class for converting between a Date object and a set of integer fields such as
YEAR, MONTH, DAY, HOUR, and so on. (A Date object represents a specific instant in time with millisecond
precision. See Date for information about the Date class.)
Subclasses of Calendar interpret a Date according to the rules of a specific calendar system.
Like other locale-sensitive classes, Calendar provides a class method, getInstance, for getting a
generally useful object of this type.
Calendar rightNow = Calendar.getInstance();
A Calendar object can produce all the time field values needed to implement the date-time formatting for a
particular language and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
When computing a Date from time fields, there may be insufficient information to compute the Date (such as
only year and month but no day in the month).
Insufficient information. The calendar will use default information to specify the missing fields. This may vary
by calendar; for the Gregorian calendar, the default for a field is the same as that of the start of the epoch: i.e.,
YEAR = 1970, MONTH = JANUARY, DATE = 1, etc. Note: The ambiguity in interpretation of what day
midnight belongs to, is resolved as so: midnight “belongs” to the following day.
23:59 on Dec 31, 1969 < 00:00 on Jan 1, 1970.
12:00 PM is midday, and 12:00 AM is midnight.
11:59 PM on Jan 1 < 12:00 AM on Jan 2 < 12:01 AM on Jan 2.
11:59 AM on Mar 10 < 12:00 PM on Mar 10 < 12:01 PM on Mar 10.
24:00 or greater are invalid. Hours greater than 12 are invalid in AM/PM mode. Setting the time will never
change the date.
If equivalent times are entered in AM/PM or 24 hour mode, equality will be determined by the actual time
rather than the entered time.
This class has been subset for J2ME based on the JDK 1.3 Calendar class. Many methods and variables have
been pruned, and other methods simplified, in an effort to reduce the size of this class.


Fields
static int AM
static int AM_PM

static int APRIL
static int AUGUST
static int DATE
static int DAY_OF_MONTH
static int DAY_OF_WEEK
static int DECEMBER
static int FEBRUARY
protected int[] fields
static int FRIDAY
static int HOUR
static int HOUR_OF_DAY
protected boolean[] isSet
static int JANUARY
static int JULY
static int JUNE
static int MARCH
static int MAY
static int MILLISECOND
static int MINUTE
static int MONDAY
static int MONTH
static int NOVEMBER
static int OCTOBER
static int PM
static int SATURDAY
static int SECOND
static int SEPTEMBER
static int SUNDAY
static int THURSDAY
protected long time
static int TUESDAY
static int WEDNESDAY
static int YEAR
Constructors
protected Calendar()
Methods
boolean after(java.lang.Object when)
boolean before(java.lang.Object when)
protected abstract
void
computeFields()
protected abstract
void
computeTime()
boolean equals(java.lang.Object obj)
int get(int field)
static Calendar getInstance()
static Calendar getInstance(TimeZone zone)
Date getTime()
protected long getTimeInMillis()
TimeZone getTimeZone()
void set(int field, int value)
void setTime(Date date)
protected void setTimeInMillis(long millis)
void setTimeZone(TimeZone value)


Methods inherited from class Object
getClass(), hashCode(), notify(), notifyAll(), toString(), wait(), wait(), wait()


Fields
YEAR
Declaration:
public static final int YEAR
Description:
Field number for get and set indicating the year. This is a calendar-specific value.
MONTH
Declaration:
public static final int MONTH
Description:
Field number for get and set indicating the month. This is a calendar-specific value.
DATE
Declaration:
public static final int DATE
Description:
Field number for get and set indicating the day of the month. This is a synonym for DAY_OF_MONTH.
See Also: DAY_OF_MONTH
DAY_OF_MONTH
Declaration:
public static final int DAY_OF_MONTH
Description:
Field number for get and set indicating the day of the month. This is a synonym for DATE.
See Also: DATE
DAY_OF_WEEK
Declaration:
public static final int DAY_OF_WEEK

Description:
Field number for get and set indicating the day of the week.
AM_PM
Declaration:
public static final int AM_PM
Description:
Field number for get and set indicating whether the HOUR is before or after noon. E.g., at 10:04:15.250
PM the AM_PM is PM.
See Also: AM, PM, HOUR
HOUR
Declaration:
public static final int HOUR
Description:
Field number for get and set indicating the hour of the morning or afternoon. HOUR is used for the 12-
hour clock. E.g., at 10:04:15.250 PM the HOUR is 10.
See Also: AM_PM, HOUR_OF_DAY
HOUR_OF_DAY
Declaration:
public static final int HOUR_OF_DAY
Description:
Field number for get and set indicating the hour of the day. HOUR_OF_DAY is used for the 24-hour
clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.
MINUTE
Declaration:
public static final int MINUTE
Description:
Field number for get and set indicating the minute within the hour. E.g., at 10:04:15.250 PM the
MINUTE is 4.
SECOND
Declaration:
public static final int SECOND
Description:
Field number for get and set indicating the second within the minute. E.g., at 10:04:15.250 PM the
SECOND is 15.
MILLISECOND
Declaration:
public static final int MILLISECOND

SUNDAY
258
Description:
Field number for get and set indicating the millisecond within the second. E.g., at 10:04:15.250 PM the
MILLISECOND is 250.
SUNDAY
Declaration:
public static final int SUNDAY
Description:
Value of the DAY_OF_WEEK field indicating Sunday.
MONDAY
Declaration:
public static final int MONDAY
Description:
Value of the DAY_OF_WEEK field indicating Monday.
TUESDAY
Declaration:
public static final int TUESDAY
Description:
Value of the DAY_OF_WEEK field indicating Tuesday.
WEDNESDAY
Declaration:
public static final int WEDNESDAY
Description:
Value of the DAY_OF_WEEK field indicating Wednesday.
THURSDAY
Declaration:
public static final int THURSDAY
Description:
Value of the DAY_OF_WEEK field indicating Thursday.
FRIDAY
Declaration:
public static final int FRIDAY
Description:
Value of the DAY_OF_WEEK field indicating Friday.
SATURDAY
Declaration:
public static final int SATURDAY

Description:
Value of the DAY_OF_WEEK field indicating Saturday.
JANUARY
Declaration:
public static final int JANUARY
Description:
Value of the MONTH field indicating the first month of the year.
FEBRUARY
Declaration:
public static final int FEBRUARY
Description:
Value of the MONTH field indicating the second month of the year.
MARCH
Declaration:
public static final int MARCH
Description:
Value of the MONTH field indicating the third month of the year.
APRIL
Declaration:
public static final int APRIL
Description:
Value of the MONTH field indicating the fourth month of the year.
MAY
Declaration:
public static final int MAY
Description:
Value of the MONTH field indicating the fifth month of the year.
JUNE
Declaration:
public static final int JUNE
Description:
Value of the MONTH field indicating the sixth month of the year.
JULY
Declaration:
public static final int JULY
Description:
Value of the MONTH field indicating the seventh month of the year.

AUGUST
Declaration:
public static final int AUGUST
Description:
Value of the MONTH field indicating the eighth month of the year.
SEPTEMBER
Declaration:
public static final int SEPTEMBER
Description:
Value of the MONTH field indicating the ninth month of the year.
OCTOBER
Declaration:
public static final int OCTOBER
Description:
Value of the MONTH field indicating the tenth month of the year.
NOVEMBER
Declaration:
public static final int NOVEMBER
Description:
Value of the MONTH field indicating the eleventh month of the year.
DECEMBER
Declaration:
public static final int DECEMBER
Description:
Value of the MONTH field indicating the twelfth month of the year.
AM
Declaration:
public static final int AM
Description:
Value of the AM_PM field indicating the period of the day from midnight to just before noon.
PM
Declaration:
public static final int PM
Description:
Value of the AM_PM field indicating the period of the day from noon to just before midnight.

fields
Declaration:
protected int[] fields
Description:
The field values for the currently set time for this calendar.
isSet
Declaration:
protected boolean[] isSet
Description:
The flags which tell if a specified time field for the calendar is set. This is an array of FIELD_COUNT
booleans,
time
Declaration:
protected long time
Description:
The currently set time for this calendar, expressed in milliseconds after January 1, 1970, 0:00:00 GMT.
Constructors
Calendar()
Declaration:
protected Calendar()
Description:
Constructs a Calendar with the default time zone.
See Also: TimeZone.getDefault()
Methods
getTime()
Declaration:
public final java.util.Date getTime()
Description:
Gets this Calendar’s current time.
Returns: the current time.
See Also: setTime(Date)
setTime(Date)
Declaration:
public final void setTime(java.util.Date date)


getInstance()
262
Description:
Sets this Calendar’s current time with the given Date.
Note: Calling setTime() with Date(Long.MAX_VALUE) or Date(Long.MIN_VALUE) may yield
incorrect field values from get().
Parameters:
date - the given Date.
See Also: getTime()
getInstance()
Declaration:
public static java.util.Calendar getInstance()
Description:
Gets a calendar using the default time zone.
Returns: a Calendar.
getInstance(TimeZone)
Declaration:
public static java.util.Calendar getInstance(java.util.TimeZone zone)
Description:
Gets a calendar using the specified time zone.
Parameters:
zone - the time zone to use
Returns: a Calendar.
getTimeInMillis()
Declaration:
protected long getTimeInMillis()
Description:
Gets this Calendar’s current time as a long expressed in milliseconds after January 1, 1970, 0:00:00 GMT
(the epoch).
Returns: the current time as UTC milliseconds from the epoch.
See Also: setTimeInMillis(long)
setTimeInMillis(long)
Declaration:
protected void setTimeInMillis(long millis)
Description:
Sets this Calendar’s current time from the given long value.
Parameters:
millis - the new time in UTC milliseconds from the epoch.
See Also: getTimeInMillis()

get(int)
Declaration:
public final int get(int field)
Description:
Gets the value for a given time field.
Parameters:
field - the given time field (either YEAR, MONTH, DATE, DAY_OF_WEEK, HOUR_OF_DAY,
HOUR, AM_PM, MINUTE, SECOND, or MILLISECOND
Returns: the value for the given time field.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the parameter is not one of the above.
set(int, int)
Declaration:
public final void set(int field, int value)
Description:
Sets the time field with the given value.
Parameters:
field - the given time field.
value - the value to be set for the given time field.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if an illegal field parameter is received.
equals(Object)
Declaration:
public boolean equals(java.lang.Object obj)
Description:
Compares this calendar to the specified object. The result is true if and only if the argument is not null
and is a Calendar object that represents the same calendar as this object.
Overrides: equals in class Object
Parameters:
obj - the object to compare with.
Returns: true if the objects are the same; false otherwise.
before(Object)
Declaration:
public boolean before(java.lang.Object when)
Description:
Compares the time field records. Equivalent to comparing result of conversion to UTC.
Parameters:
when - the Calendar to be compared with this Calendar.
Returns: true if the current time of this Calendar is before the time of Calendar when; false otherwise.

after(Object)
Declaration:
public boolean after(java.lang.Object when)
Description:
Compares the time field records. Equivalent to comparing result of conversion to UTC.
Parameters:
when - the Calendar to be compared with this Calendar.
Returns: true if the current time of this Calendar is after the time of Calendar when; false otherwise.
setTimeZone(TimeZone)
Declaration:
public void setTimeZone(java.util.TimeZone value)
Description:
Sets the time zone with the given time zone value.
Parameters:
value - the given time zone.
See Also: getTimeZone()
getTimeZone()
Declaration:
public java.util.TimeZone getTimeZone()
Description:
Gets the time zone.
Returns: the time zone object associated with this calendar.
See Also: setTimeZone(TimeZone)
computeFields()
Declaration:
protected abstract void computeFields()
Description:
Converts the current millisecond time value time to field values in fields[]. This allows you to sync up
the time field values with a new time that is set for the calendar.
computeTime()
Declaration:
protected abstract void computeTime()
Description:
Converts the current field values in fields[] to the millisecond time value time.













No comments:

Post a Comment