A small but ’real’ post. Twitter stores all dates in a well, nonstandard way, so i came up with the following extension for my project to handle this:
public static class Extensions
{
public static DateTime ParseTwitterTime(this string date)
{
const string format = "ddd, dd MMM yyyy HH:mm:ss zzzz";
return DateTime.ParseExact(date, format, CultureInfo.InvariantCulture);
}
}
What i does is takes the string from the XML response formatted like this “Wed, 08 Apr 2009 19:22:10 +0000″ and parses it as an DateTime. Having it as an extension allows me to use in inside LINQ queries.
(And I needed something to test the SyntaxHighlighter script)
Updated 2010-09-06: Twitter changed it’s format in the api
Very helpful!
Thanks.
Hi Fredrik,
Thanks for sharing. I’ve found that Twitter is giving me dates like “Mon Nov 12 09:53:26 +0000 2012″, so I am using
const string format = “ddd MMM dd HH:mm:ss zzzz yyyy”;
Dunno if twitter localises these based on your request, or if they just change over time?
David
Thanks you so much man, i used this “ddd MMM dd HH:mm:ss zzzz yyyy”; format but you helped me…
good coding…