格式化pubDate RSS

时间:2017-12-03 21:18:21

标签: c#

下午好。我决定从论坛的某个主题中获取新闻,这并不困难。但问题出现了如何将pubDate属性更改为24小时格式。目前,每个主题的格式为12/3/2017 2:57:55 PM。我想12/3/2017 14:57:55。或者你可以在2017年12月3日完成。帮助请更正代码。谢谢!

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using Classes;

namespace controls
{
    public partial class News : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.PopulateRssFeed();
        }

        private void PopulateRssFeed()
        {
            string RssFeedUrl = ConfigurationManager.AppSettings["RssFeedUrl"];
            string RssMaxNews = ConfigurationManager.AppSettings["RssMaxNews"];

            List<Feeds> feeds = new List<Feeds>();
            try
            {
                XDocument xDoc = new XDocument();
                xDoc = XDocument.Load(RssFeedUrl);
                var items = (from x in xDoc.Descendants("item")
                             select new
                             {
                                 title = x.Element("title").Value,
                                 link = x.Element("link").Value,
                                 pubDate = x.Element("pubDate").Value,
                                 description = x.Element("description").Value,
                             }).Take(10).ToList();
                if (items != null)
                {
                    foreach (var i in items)
                    {
                        Feeds f = new Feeds
                        {
                            Title = i.title,
                            Link = i.link,
                            PublishDate = i.pubDate,
                            Description = i.description
                        };

                        feeds.Add(f);
                    }
                }

                gvRss.DataSource = feeds;
                gvRss.DataBind();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}

0 个答案:

没有答案