2011-08-04 16 views
0

私はFacebookのステータスフィードをYahooパイプ経由で実行しており、自分のホストされているWebサイトのページに出力/埋め込みしています。ASP.NETで日付をフォーマットする方法

XMLフィードには日付が含まれています。私は日付をフォーマットしたいが、方法を知らない。 XML部分は日付出力です... <pubDate>Thu, 14 Jul 2011 20:38:07 +0100</pubDate>と私は14/07/2011のようなものをレンダリングしたいと思います。

ご迷惑をおかけして申し訳ございません。あなたがDateTime.ParseまたはDateTime.ParseExactを使用して、日付を保存することができます

protected void Page_Load(object sender, EventArgs e) 
    { 

     WebRequest MyRssRequest = WebRequest.Create("http://pipes.yahoo.com/pipes/pipe.run?FacebookRssUrl=http%3A%2F%2Fwww.facebook.com%2Ffeeds%2Fpage.php%3Fid%3D456456456456456%26format%3Drss20&_id=456456456456456456464&_render=rss"); 
     WebResponse MyRssResponse = MyRssRequest.GetResponse(); 

     Stream MyRssStream = MyRssResponse.GetResponseStream(); 

     // Load previously created XML Document 
     XmlDocument MyRssDocument = new XmlDocument(); 
     MyRssDocument.Load(MyRssStream); 

     XmlNodeList MyRssList = MyRssDocument.SelectNodes("rss/channel/item"); 

     string sTitle = ""; 
     string sLink = ""; 
     string sDescription = ""; 

     // Iterate/Loop through RSS Feed items 
     for (int i = 0; i < 3; i++) 
     { 
      XmlNode MyRssDetail; 

      MyRssDetail = MyRssList.Item(i).SelectSingleNode("title"); 
      if (MyRssDetail != null) 
       sTitle = MyRssDetail.InnerText; 
      else 
       sTitle = ""; 

      MyRssDetail = MyRssList.Item(i).SelectSingleNode("link"); 
      if (MyRssDetail != null) 
       sLink = MyRssDetail.InnerText; 
      else 
       sLink = ""; 

      MyRssDetail = MyRssList.Item(i).SelectSingleNode("pubDate"); 
      if (MyRssDetail != null) 
       sDescription = MyRssDetail.InnerText; 

      else 
      { 
       sDescription = ""; 
      } 

      // Now generating HTML table rows and cells based on Title,Link & Description 
      HtmlTableCell block = new HtmlTableCell(); 
      block.InnerHtml = "<span style='font-weight:bold'><a href='" + sLink + "' target='new'>"+ sTitle + "</a></span>"; 
      HtmlTableRow row = new HtmlTableRow(); 
      row.Cells.Add(block); 
      tbl_Feed_Reader.Rows.Add(row); 
      HtmlTableCell block_description = new HtmlTableCell(); 
      block_description.InnerHtml = "<p align='justify'>" + sDescription + "</p>"; 
      HtmlTableRow row2 = new HtmlTableRow(); 
      row2.Cells.Add(block_description); 
      tbl_Feed_Reader.Rows.Add(row2); 
     } 
    } 
+0

あなたの質問は非常に明確ではありません。それを読んで、それが意味をなさないかどうかを見て、それを編集して、人々があなたが求めていることを理解できるようにしてください。 – Oded

答えて

0

あなたが必要とするDateTimeとrender it in specific formatに解析できます。そして、そこから行く、

sDescription = String.Format("{0:D}", MyRssDetail.InnerText); 

をまたは日付に変換します:

var x = DateTime.Parse(MyRssDetail.InnerText); 
//Your date format 
sDescription = x.ToString("d MMM yyyy"); 
+0

申し訳ありませんが、あなたに戻って遅くなります。それは大変感謝しました。 –

0

私はC#のコードを持っています...。そこから

DateTime xmlDateTime = DateTime.Parse(xmlValue); 

は、それが目的の形式のパラメータでDateTime.ToString()を使用して、それを出力する問題(または内蔵のToShortDateString、ToLongDateString、ToShortTimeString、などのいずれか)

xmlDateTime.ToShortDateString(); 
0

私はどうなるのです何かのように:

DateTime parsedDate=DateTime.Min; 
if(DateTime.TryParse(xmlStringWithDate,ref parsedDate)) 
{ 
    //Do something useful with parsedDate since the parse was successful 
} 
0
String.Format({0:D}, dateToFormat) 

私はあなたがpubDateのをやりたいと仮定していますか?

sDescription = String.Format({0:D}, MyRssDetail.InnerText.ToDate()) 
0

これを行うには、String.Formatのを使用することができ

sDescription = Convert.ToDateTime(MyRssDetail.InnerText).toShortDateString(); 
関連する問題