FileDocCategorySizeDatePackage
CalendarImpl.javaAPI DocphoneME MR2 API (J2ME)5175Wed May 02 17:59:56 BST 2007com.sun.cldc.util.j2me

CalendarImpl

public class CalendarImpl extends Calendar
This class is an implementation of the subsetted CLDC Calendar class.
see
java.util.TimeZone

Fields Summary
private static final String[]
months
Constructors Summary
public CalendarImpl()

    super();
  
Methods Summary
public longgetMilliseconds()
Gets this CalendarImpl's current time as a long.

return
the current time as UTC milliseconds from the epoch.

 return getTimeInMillis(); 
public voidread(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.

param
input the input object to read from

    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 voidsetMilliseconds(long millis)
Sets this calendar's current time from the given long value.

param
millis the new time in UTC milliseconds from the epoch.

 setTimeInMillis(millis); 
public java.lang.StringtoString()
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.StringtwoDigitString(int field)


       
    if (field == 0)
      return "00";
    else if (field < 10)
      return "0"+Integer.toString(field);
    else
      return Integer.toString(field);
  
public voidwrite(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->)

param
output the output object to write to
see
#read(DataInput)

    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);