|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
Object
Calendar
public class Calendar
Calendar is a class for getting and setting dates
using a set of integer fields such as
YEAR, MONTH, DAY.
The fields are accessed directly in the code without a prefix:
Calendar cal = new Calendar(); // using the operator get [] and a constant field name int today = cal[DAY_OF_WEEK];
Calendar data can be accessed using the in-built operators
get and set with brackets.
The following constant fields from API are used with Calendar:
The following constant fields from API are used with Calendar for formatting:
| Constructor Summary | |
|---|---|
Calendar()
Creates a calendar using the default time zone and locale. |
|
Calendar(TimeZone timeZone)
Creates a calendar using the time zone given as argument and default locale. |
|
| Method Summary | |
|---|---|
boolean |
after(Calendar when)
Compares the time field records. |
boolean |
before(Calendar when)
Compares the time field records. |
Calendar |
copy()
Creates a copy from this calendar instance. |
String |
format(int format)
Formats calendars date and/or time as string according to current locale/language. |
long |
getMillis()
Gets this Calendar's current time as a long expressed in milliseconds after January 1, 1970, 0:00:00 GMT (the epoch). |
TimeZone |
getTimeZone()
Gets the TimeZone for this Calendar object. |
int |
operator_get(int field)
Gets the value for a given time field. |
void |
operator_set(int field,
int value)
Sets the time field with the given value. |
void |
set(int year,
int month,
int date)
Sets the values for the fields year, month, and date. |
void |
set(int year,
int month,
int date,
int hour,
int minute)
Sets the values for the fields year, month, date, hour, and minute. |
void |
set(int year,
int month,
int date,
int hour,
int minute,
int second)
Sets the values for the fields year, month, date, hour, minute, and second. |
void |
setMillis(long millis)
Sets this Calendar's current time from the given long value. |
void |
setTimeZone(TimeZone timeZone)
Sets the TimeZone for this Calendar object. |
| Methods inherited from class Object |
|---|
toString, equals, hashCode |
| Methods inherited from |
|---|
equals, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Calendar()
Calendar is based on the current time
in the default time zone with the default locale.
public Calendar(TimeZone timeZone)
timeZone - time zone| Method Detail |
|---|
public int operator_get(int field)
field - the given time field.
public void operator_set(int field,
int value)
field - the given time field.value - the value to be set for the given time field.public boolean after(Calendar when)
when - the Calendar to be compared with this Calendar.
public boolean before(Calendar when)
when - the Calendar to be compared with this Calendar.
public void set(int year,
int month,
int date)
clear first.
year - the value used to set the YEAR time field.month - the value used to set the MONTH time field.
Month value is 0-based. e.g., 0 for January.date - the value used to set the DATE time field.
public void set(int year,
int month,
int date,
int hour,
int minute)
clear first.
year - the value used to set the YEAR time field.month - the value used to set the MONTH time field.
Month value is 0-based. e.g., 0 for January.date - the value used to set the DATE time field.hour - the value used to set the HOUR_OF_DAY time field.minute - the value used to set the MINUTE time field.
public void set(int year,
int month,
int date,
int hour,
int minute,
int second)
clear first.
year - the value used to set the YEAR time field.month - the value used to set the MONTH time field.
Month value is 0-based. e.g., 0 for January.date - the value used to set the DATE time field.hour - the value used to set the HOUR_OF_DAY time field.minute - the value used to set the MINUTE time field.second - the value used to set the SECOND time field.public long getMillis()
setMillis(long)public void setMillis(long millis)
millis - the new time in UTC milliseconds from the epoch.getMillis()public String format(int format)
format - FORMAT_DATE, FORMAT_TIME or FORMAT_DATETIME.public Calendar copy()
public TimeZone getTimeZone()
TimeZone for this Calendar object.
public void setTimeZone(TimeZone timeZone)
TimeZone for this Calendar object.
timeZone - new time zone
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||