开发者

Format 2 strings to RSS PubDate

ive got 2 strings, date:"27.03.11 " and time:"15:04", whi开发者_JAVA技巧ch 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?


Use the following steps:

  • Parse the date and time strings into one DateTime variable. Use the DateTime.ParseExact static method for this.
  • Convert the datetime to GMT using the methods of the TimeZone class (if desired---I don't think this is mandatory according to the RSS specification).
  • 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:

    • Standard Date and Time Format Strings
    • Custom Date and Time Format Strings

Since RSS requires dates to be in the RFC 822 format, the following related SO question might help you with the last step:

  • How do I parse and convert DateTime’s to the RFC 822 date-time format?

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜