如何将 DateTimeOffset 转换为 Twitter 日期/时间?

发布于 2024-09-03 05:32:59 字数 193 浏览 14 评论 0原文

如何将 DateTimeOffset.Now 转换为 twitter 兼容的日期/时间?

Twitter 示例:

<created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>

干杯 :)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑红尘 2024-09-10 05:32:59

几乎做到了:

DateTimeOffset now = DateTimeOffset.Now;        
string x = now.ToString("ddd MMM dd HH:mm:ss zzzz yyyy",
                        CultureInfo.InvariantCulture);
Console.WriteLine(x);

...但它最终以时区位中的冒号结束。我现在正在考虑删除它。

编辑:布莱奇。我现在能做的就是:

    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);

这太丑了。请注意,这是一个非常丑陋的日期和时间格式。 Twitter 真的没有更明智的格式可供您使用吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文