Reputation: 313
ive got 2 strings, date:"27.03.11 " and time:"15:04", which id like to format as a PubDate elemnt for a rss file like Fri, 18 Nov 2005 19:12:30 GMT. How can i do this in c sharp?
Upvotes: 1
Views: 1844
Reputation: 172220
Use the following steps:
DateTime
variable. Use the DateTime.ParseExact static method for this.Format this variable into a string using the DateTime.ToString method. The following MSDN pages will help you choose the correct format string based on your needs:
Since RSS requires dates to be in the RFC 822 format, the following related SO question might help you with the last step:
EDIT: For the first step, have a look at this example:
var s = "27.03.11 15:04";
var dtm = DateTime.ParseExact(s, @"dd.MM.yy HH\:mm", null);
(The \:
ensures that :
is seen as a literal :
rather than a culture-specific time separator.)
Upvotes: 2