0

我正在尝试解析美联社的 RSS 提要,但日期确实让我感到困惑。以下是提要中一项的示例:

<entry>
    <id>urn:publicid:ap.org:Hosted2Syndication:b7f6d88749d341aa9a30e15dcb983b41</id>
    <title type="text">9/11 defendants ignore judge at Guantanamo hearing</title>
    <summary type="text">GUANTANAMO BAY NAVAL BASE, Cuba (AP) — They knelt in prayer, ignored the judge and wouldn't listen to Arabic translations as they confronted nearly 3,000 counts of murder. The self-proclaimed mastermind of the Sept. 11 attacks and four co-defendants defiantly disrupted an arraignment that dragged into Saturday night in the opening act of the long-stalled effort to prosecute them in a military court.</summary>
    <published>2012-05-05T22:38:59-04:00</published>
    <updated>2012-05-05T20:28:08-04:00</updated>
    <author />
    <link rel="alternate" type="text/html" title="AP Article" href="http://hosted2.ap.org/APDEFAULT/3d281c11a96b4ad082fe88aa0db04305/Article_2012-05-05-Guantanamo-Sept%2011%20Trial/id-b7f6d88749d341aa9a30e15dcb983b41" />
    <content type="xhtml"></content>
</entry>

所以发布日期是:2012-05-05T22:38:59-04:00

如果您在浏览器中查看此项目,则日期显示为:May. 5, 2012 8:28 PM ET

但是,当我将其转换为代码中的日期时:

DateTime date;

DateTime.TryParse("2012-05-05T22:38:59-04:00", out date);

它的出现是:5/5/2012 10:38:59 PM

我不知道为什么网站显示的日期相差 2 小时。

您可能会看到与当前提要中的任何项目的区别:

http://hosted2.ap.org/atom/APDEFAULT/3d281c11a96b4ad082fe88aa0db04305

4

1 回答 1

0

当您加载实际故事时,您正确地看到了<updated>2012-05-05T20:28:08-04:00</updated>文章中的日期/时间May. 5, 2012 8:28 PM ET

20:28:08 (GMT-4) == 8:28 PM (ET)

您的 C# 代码很好,但您必须向美联社询问为什么这篇文章最后一次更新是在实际发布前两个小时。

于 2012-05-06T03:01:32.287 回答