在 C# 中获取具有 2 位数年份的文化特定日期

发布于 2024-12-29 03:05:33 字数 200 浏览 8 评论 0原文

我正在更新一些使用“MM/dd/yy”将日期格式化为字符串的代码。我需要它具有文化意识,但想保留两位数年份以保持日期简短。以下是我想到的,但是有更好的方法吗?

string dateFormat = culture_Info.DateTimeFormat.ShortDatePattern.Replace("yyyy", "yy");

I'm updating some code that formats a date to a string using "MM/dd/yy". I need it to be culture aware, but want to keep the two digit year in order to keep the date short. Below is what I came up with, but is there a better way?

string dateFormat = culture_Info.DateTimeFormat.ShortDatePattern.Replace("yyyy", "yy");

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

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

发布评论

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

评论(2

我喜欢麦丽素 2025-01-05 03:05:33

我不知道有什么办法,不(而且我已经相当广泛地查看了格式)。显然,你所得到的东西仍然会在嘴里留下一点难闻的味道,但我认为这是你能做的最好的事情了。

I don't know of any way, no (and I've looked at the formatting reasonably extensively). What you've got obviously still leaves a bit of a nasty taste in the mouth, but I think it's the best you can do.

弄潮 2025-01-05 03:05:33

正如乔恩所说,我不认为有任何方法可以默认执行您想要的操作。但真正的问题是:你真的需要这样做吗?毕竟,这样做只会获得几个字节。值得“嘴里有难闻的味道”吗?

As Jon says, I don't believe there is any way to do what you want by default. But the real question is: do you really need to do it? You're only gaining a couple of bytes by doing so, after all. Is it worth the "nasty taste in the mouth?"

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