开发者

How can I convert my DateTimeOffset to a Twitter Date/Time?

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>
开发者_如何学Python

cheers :)


This nearly does it:

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜