code: public static void formatDate(StringBuffer buf,Calendar calendar, boolean cookie)
      {
          // "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
          // "EEE, dd-MMM-yy HH:mm:ss 'GMT'",     cookie
          
          int day_of_week  = calendar.get(Calendar.DAY_OF_WEEK);
          int day_of_month = calendar.get(Calendar.DAY_OF_MONTH);
          int month = calendar.get(Calendar.MONTH);
          int year = calendar.get(Calendar.YEAR);
          int century = year/100;
          year=year%100;
  
          long tm = (calendar instanceof HttpCal)?(((HttpCal)calendar).getTimeInMillis()):calendar.getTime().getTime();
          int epoch=(int)((tm/1000) % (60*60*24));
          int seconds=epoch%60;
          epoch=epoch/60;
          int minutes=epoch%60;
          int hours=epoch/60;
          
          buf.append(DAYS[day_of_week]);
          buf.append(',');
          buf.append(' ');
          StringUtil.append2digits(buf,day_of_month);
          
          if (cookie)
          {
              buf.append('-');
              buf.append(MONTHS[month]);
              buf.append('-');
              StringUtil.append2digits(buf,year);
          }
          else
          {
              buf.append(' ');
              buf.append(MONTHS[month]);
              buf.append(' ');
              StringUtil.append2digits(buf,century);
              StringUtil.append2digits(buf,year);
          }
          buf.append(' ');
          StringUtil.append2digits(buf,hours);
          buf.append(':');
          StringUtil.append2digits(buf,minutes);
          buf.append(':');
          StringUtil.append2digits(buf,seconds);
          buf.append(" GMT");
      }
docs: Format HTTP date
  "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or
  "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies