format static method

String format(
  1. DateTime date
)

Format a date according to RFC-1123, e.g. Thu, 1 Jan 1970 00:00:00 GMT.

Implementation

static String format(DateTime date) {
  const List wkday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
  const List month = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec",
  ];

  DateTime d = date.toUtc();
  StringBuffer sb =
      StringBuffer()
        ..write(wkday[d.weekday - 1])
        ..write(", ")
        ..write(d.day <= 9 ? "0" : "")
        ..write(d.day.toString())
        ..write(" ")
        ..write(month[d.month - 1])
        ..write(" ")
        ..write(d.year.toString())
        ..write(d.hour <= 9 ? " 0" : " ")
        ..write(d.hour.toString())
        ..write(d.minute <= 9 ? ":0" : ":")
        ..write(d.minute.toString())
        ..write(d.second <= 9 ? ":0" : ":")
        ..write(d.second.toString())
        ..write(" GMT");
  return sb.toString();
}