CalendarImplpublic class CalendarImpl extends Calendar This class is an implementation of the subsetted CLDC
Calendar class. |
Fields Summary |
---|
private static final String[] | months |
Constructors Summary |
---|
public CalendarImpl()
super();
|
Methods Summary |
---|
public long | getMilliseconds()Gets this CalendarImpl's current time as a long. return getTimeInMillis();
| public void | read(java.io.DataInput input)Read the packed time value from a data input object.
The packed time is not the milliseconds, but is the local
time (not timezone) packed into a pair of integers.
The time is packed into the first integer, followed by the date.
time: millis (bit 0-9), seconds (bit 10-15), minutes (bit 16-21),
hours (bit 22-26)
date: day of month (bit 0-4), month (bit 5-8), year (bit 9->)
It uses input.readInt() to get an integer
packed representation of the date. Then it sets the calendar's
fields using this date.
int packed_time = input.readInt();
int packed_date = input.readInt();
set(HOUR_OF_DAY, packed_time >> 22);
set(MINUTE, packed_time >> 16);
set(SECOND, packed_time >> 10);
set(MILLISECOND, packed_time);
set(YEAR, packed_date >> 9);
set(MONTH, packed_date >> 5);
set(DATE, packed_date);
| public void | setMilliseconds(long millis)Sets this calendar's current time from the given long value. setTimeInMillis(millis);
| public java.lang.String | toString()Create a string representing the date and time using the following format:
Sun, 06 Nov 1994 08:49:37 GMT
(The preferred Internet standard,
a fixed-length subset of that defined by RFC 1123, which is an update to RFC 822).
String str;
switch (get(DAY_OF_WEEK)) {
case SUNDAY: str = "Sun, "; break;
case MONDAY: str = "Mon, "; break;
case TUESDAY: str = "Tue, "; break;
case WEDNESDAY: str = "Wed, "; break;
case THURSDAY: str = "Thu, "; break;
case FRIDAY: str = "Fri, "; break;
case SATURDAY: str = "Sat, "; break;
default: str = get(DAY_OF_WEEK) + ", "; break;
}
return str +
twoDigitString(get(DATE)) + " " +
months[get(MONTH)] + " " +
get(YEAR) + " " +
twoDigitString(get(HOUR_OF_DAY)) + ":" +
twoDigitString(get(MINUTE)) + ":" +
twoDigitString(get(SECOND)) + " " +
getTimeZone().getID();
| private final java.lang.String | twoDigitString(int field)
if (field == 0)
return "00";
else if (field < 10)
return "0"+Integer.toString(field);
else
return Integer.toString(field);
| public void | write(java.io.DataOutput output)Write the packed time value to a data output object. (The packed time is
not the milliseconds, but is the local time (not including timezone
packed into a long integer.)
It packs the calendar fields into a pair of integers, then uses
output.writeInt() to write the integers.
The time is packed into the first integer, followed by the date.
time: millis (bit 0-9), seconds (bit 10-15), minutes (bit 16-21),
hours (bit 22-26)
date: day of month (bit 0-4), month (bit 5-8), year (bit 9->)
int packed_time;
int packed_date;
packed_time = (get(HOUR_OF_DAY) << 22) | (get(MINUTE) << 16) |
(get(SECOND) << 10) | get(MILLISECOND);
packed_date = (get(YEAR) << 9) | (get(MONTH) << 5) | get(DATE);
output.writeInt(packed_time);
output.writeInt(packed_date);
|
|