SQL 日期格式的 C-Sharp 日期时间文化格式

发布于 2025-01-12 14:38:11 字数 110 浏览 1 评论 0原文

这种日期格式有文化吗?

2022-03-08 23:59:59

或者我是否必须使用 .ToString() 手动执行此操作?

Is there a culture for this date-format?

2022-03-08 23:59:59

Or do I have to do this manualy with .ToString()?

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

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

发布评论

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

评论(1

来日方长 2025-01-19 14:38:11

是否有一种文化可以确保 DateTime.ToString 输出这种格式,这很重要吗?重要的是您是否想以文化上合适的格式输出 DateTime。如果你不关心(给定的)文化,你为什么要要求它?

如果您需要的只是 DateTime 作为该格式的字符串,请使用:

string dtAsString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

Does it matter if there is a culture which ensures that DateTime.ToString will output this format? What matters is if you want to output a DateTime in a culturally appropriate format or not. If you don't care about a (given) culture, why do you ask for it?

If all you need is a DateTime as a string in that format, use:

string dtAsString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文