我从 C# 中的 DateTime 对象上的 ToString() 调用中返回了一些垃圾数据,恐怕我在摸索了一段时间后会被难住。
该函数应该格式化日期以符合 RFC 822(根据 RSS 规范的要求),如下所示:
public static string FormatPubDate(DateTime pubDate)
{
string _rfc822Format = "ddd, dd MMM yyyy HH:mm:ss";
string _tmp = pubDate.ToUniversalTime().ToString(_rfc822Format);
return pubDate.ToString(_tmp + " UT");
}
从我可以阅读的 DateTime ToString() 文档中,这应该是我想要的。
但是,对于某些日期,它会产生垃圾:
Console.WriteLine(FormatPubDate(new DateTime(2008, 12, 16, 13, 44, 33)));
Console.WriteLine(FormatPubDate(new DateTime(2008, 12, 17, 13, 44, 33)));
Console.WriteLine(FormatPubDate(new DateTime(2009, 3, 18, 4, 17, 20)));
Console.WriteLine(FormatPubDate(new DateTime(2009, 4, 30, 10, 44, 33)));
产量:
Tue, 16 Dec 2008 19:44:33 UT
We17, 17 Dec 2008 19:44:33 UT
We18, 18 3ar 2009 09:17:20 UT
T10u, 30 Apr 2009 15:44:33 UT
任何想法为什么它返回 We18 而不是 Wed 和 3ar 而不是 Mar?