text: import java.util.Calendar;
  import java.util.TimeZone;
  import divconq.;
  Parserfor the HTTP date format. This will parse the 3 formats that are acceptable for the HTTP/1.1 date. The three formats that are acceptable for the HTTP-date are
  This can also parse the date in ms as retrived from the
  System's
  System.currentTimeMillis method. This has a parse method for a
  long which will do the same as the
  parse(String).
  Once the date has been parsed there are two methods that allow the date
  to be represented, the
  toLong method converts the date to a
  long and the
  toString method will convert the date
  into a
  String.
  This produces the same string as the
  SimpleDateFormat.format
  using the pattern
  "EEE, dd MMM yyyy hh:mm:ss 'GMT'". This will
  however do the job faster as it does not take arbitrary inputs.
  public class DateParser extends Parser {
  private static final TimeZone ZONE = TimeZone.getTimeZone("GMT");
  private static final String WEEKDAYS[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
  private static final String MONTHS[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  long time = System.currentTimeMillis();
  return new DateParser(time).toString();
  public DateParser(){
  public DateParser(long date){
  public DateParser(String date) {
  long. If this method is given the value of the date as a
  longit will construct the RFC 1123 date as required by RFC 2616 sec 3.3.
  This saves time on parsing a
  String that is encoded in
  the HTTP-date format. The date given must be positive, if the date
  given is not a positive '
  long' then the results
  of this method is random/unknown.
  datethe date to be parsed
  Calendar calendar = Calendar.getInstance(ZONE);
  calendar.setTimeInMillis(date);
  weekday = calendar.get(DAY_OF_WEEK);
  day = calendar.get(DAY_OF_MONTH);
  hour = calendar.get(HOUR_OF_DAY);
  Dateobjects.
  datethe date specified in on of the HTTP date formats
  datethe date specified as a long of milliseconds
  buf. This checks the fourth char of the buffer to see what it contains. Invariably a date format belonging to RFC 1123 will have a ',' character in position 4, a date format belonging to asctime will have a ' ' character in position 4 and if neither of these characters are found at position 4 then it is assumed that the date is in the RFC 850 fromat, however it may not be.
  rfc1123 = 'wkday "," SP date1 SP time SP GMT'. date1 = '2DIGIT SP month SP 4DIGIT' and finally time = '2DIGIT ":" 2DIGIT ":" 2DIGIT'.
  rfc850 = 'weekday "," SP date2 SP time SP GMT'. date2 = '2DIGIT "-" month "-" 2DIGIT' and finally time = '2DIGIT ":" 2DIGIT ":" 2DIGIT'.
  asctime = 'weekday SP date3 SP time SP 4DIGIT'. date3 = 'month SP (2DIGIT | (SP 1DIGIT))' and time = '2DIGIT ":" 2DIGIT ":" 2DIGIT'.
  This may parse more than 2 digits but if there are more than 2 digits in a row then the date format is incorrect anyway.
  Tue, 02 Jun 1982. For performance reasons a string builder is used. This avoids an unneeded synchronization caused by the string buffers.
  builderthis is the builder to append the date to
  private void date(StringBuilder builder) {
  23:59:59. For performance reasons a string builder is used. This avoids an unneeded synchronization caused by the string buffers.
  builderthis is the builder to write the time to
  private void time(StringBuilder builder) {
  private void zone(StringBuilder builder) {
  Calendar calendar = Calendar.getInstance(ZONE); /* GMT*/
  calendar.set(MILLISECOND, 0);
  Tue, 02 Jun 1982 23:59:59 GMT. This uses a
  StringBufferto accumulate the various
  Strings/
  ints to form the resulting date value. The resulting date value is the one required by RFC 2616.
  The HTTP date must be in the form of RFC 1123. The hours, minutes and seconds are appended with the 0 character if they are less than 9 i.e. if they do not have two digits.
  StringBuilder builder = new StringBuilder(30);