I’m trying to parse a datestamp (that I got from Twitter) but am receiving errors. here’s the datestamp:
Fri, 27 Aug 2010 22:00:07 +0000
Here’s my code:
DateTime.ParseExact(MyDateValue, “ddd, dd MMM YYYY HH:mm:ss +ffff”, new CultureInfo(“en-US”))
and here’s my error:
System.FormatException was unhandled
Message=String was not recognized as a valid DateTime.
Anyone fancy taking that on? To make it easy I’ve provided the code below for a console app that exhibits the problem.
Thanks
Jamie
using System;
using System.Globalization;
class Program
{
static void Main(string[] args)
{
string MyDateValue = "Fri, 27 Aug 2010 22:00:07 +0000";
var dt = DateTime.ParseExact(MyDateValue, "ddd, dd MMM YYYY HH:mm:ss +ffff", new CultureInfo("en-US"));
}
}
The year specifier is
yyyy, notYYYY:The above works fine, as far as that it will not throw an exception.
I am assuming that the
+0000at the end of the string is supposed to be a timezone specifier. If so, theffffis incorrect, as it stands forThe hundred thousandths of a second, not the timezone specifier, which isK. If it is indeed supposed to be the timezone specifier, then this would be the correct code:See
Custom Date and Time Format Strings.