1

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?

kojoma
  • 313
  • 2
  • 3
  • 12
  • First, parse both into the same DateTime and use that DateTime to generate your result string – Polity May 12 '11 at 14:52

1 Answers1

2

Use the following steps:

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

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • Can u help me withe the first part? Itried the following example from a tutorial but always get the error "String was not recognized as a valid DateTime." String MyString; MyString = "1999-09-01 21:34 PM"; //MyString = "1999-09-01 21:34 p.m."; //Depends on your regional settings DateTime MyDateTime; MyDateTime = new DateTime(); MyDateTime = DateTime.ParseExact(MyString, "yyyy-MM-dd HH:mm tt", null); – kojoma May 12 '11 at 16:22
  • That date doesn't make sense: If it's 24hour time, you don't need am or pm. I've added an example for the first part to my answer. – Heinzi May 13 '11 at 10:02
  • @kojoma: PS: Don't trust that tutorial, it's bad code (for example, there's no need to set MyDateTime to "new DateTime()" before filling it with ParseExact). – Heinzi May 13 '11 at 10:05