format 静态方法
- DateTime date
根据 RFC-1123 格式化日期,例如 Thu, 1 Jan 1970 00:00:00 GMT
。
实现
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();
}