I am trying to parse dates in RFC1123 format (Thu, 21 Jan 2010 17:47:00 EST).
Here is what I tried but none worked:
DateTime Date = DateTime.Parse(dt);
DateTime Date = DateTime.ParseExact(dt, "r", null);
I am trying to parse dates in RFC1123 format (Thu, 21 Jan 2010 17:47:00 EST).
Here is what I tried but none worked:
DateTime Date = DateTime.Parse(dt);
DateTime Date = DateTime.ParseExact(dt, "r", null);
Have you tried something like:
I haven't tested it yet (will in a few moments)... but I believe that will do it for you.
Edit: It seems that the problem is that RFC1123 states that the timezone should always be GMT... which is why r or R did not work as a format for you. The problem is the EST. The pattern above accounts for EST, but it is static so if you have any other timezone you might be in trouble. The best solution would be to go with the RFC1123 standard and go to GMT and it should solve your problem. If you can't, let me know I might have a solution.
Edit 2: This is not a complete solution but what it does it isolates the timezone and still allows you to parse it. The code doesn't know the timezone that it is being presented with but you can throw any timezone abbreviation at it and it will parse the time. If you want to convert to GMT and then use r or R you can take the result of the regex match, put it against a lookup table (to see what the time offset it for that timezone abbreviation), then convert the time to GMT and parse from there. That would be a good solution but a little more work. Here's the code:
Here is a list of UTC offsets for you if you would like to turn this into a timezone converter:
Timezone Abbreviations with UTC offsets