Hi folks,
How can I convert a DateTimeOffset.Now
into a twitter-compatible date/time?
Twitter example:
<created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>
cheers :)
Hi folks,
How can I convert a DateTimeOffset.Now
into a twitter-compatible date/time?
Twitter example:
<created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>
cheers :)
This nearly does is:
DateTimeOffset now = DateTimeOffset.Now;
string x = now.ToString("ddd MMM dd HH:mm:ss zzzz yyyy",
CultureInfo.InvariantCulture);
Console.WriteLine(x);
... but it ends up with a colon in the time zone bit. I'm looking at removing that now.
EDIT: Blech. The best I can do at the moment is this:
DateTimeOffset now = DateTimeOffset.Now;
string x = now.ToString("ddd MMM dd HH:mm:ss",
CultureInfo.InvariantCulture)
+ (now.ToString(" zzzz yyyy", CultureInfo.InvariantCulture)
.Replace(":", ""));
Console.WriteLine(x);
That's incredibly ugly. Mind you, this is a really ugly date and time format. Does Twitter really not have a more sensible format you can use?