Reputation: 3329
I have a date in String format,
mm/dd/yyyy
I want to convert this to RSS date format like,
friday, june 01, 2012, 12:11:25PM
and i want to add this date value which is basically the pubDate to RSS pubDate tag, as follows:
writer.WriteElementString("pubDate",pubDate);
How can i convert this string to pubDate? any suggestions?
O/P
<?xml version="1.0" encoding="utf-8"?><rss version="2.0">
<channel>
<title>About RSS</title>
<link>http://localhost:27549/TTTT.aspx</link>
<description>The latest news</description>
<image><url>http://localhost:27549/images/ttt_logo.jpg</url></image>
<item><title>ABC</title><link>http://localhost:27549/Viewttt.aspx?id=217</link><description>zzzzzzzzzzzzzzzzzzz...</description><pubDate>Tuesday, August 30, 2011, 00:00:00AM</pubDate></item></channel></rss>
Upvotes: 0
Views: 544
Reputation: 10981
var dt=DateTime.ParseExact("06/08/2012", "MM/dd/yyyy", CultureInfo.InvariantCulture)
writer.WriteElementString("pubDate",dt.ToString("U")); // or dt.ToString("F")
Upvotes: 1
Reputation: 17724
Fisrt you convert to DateTime variable. For this you can use DateTime.ParseExact
.
Then you can use the ToString method to output the date in whatever format you want. Here is the list of custom formats
I will post an example to help you.
string str = "11/10/1984";
DateTime dt = DateTime.ParseExact(str, "dd/MM/yyyy", CultureInfo.InvariantCulture);
string formatted = dt.ToString("dddd, MMMM dd, yyyy, HH:mm:sstt");
Upvotes: 2