在 C# 中获取具有 2 位数年份的文化特定日期
我正在更新一些使用“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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有什么办法,不(而且我已经相当广泛地查看了格式)。显然,你所得到的东西仍然会在嘴里留下一点难闻的味道,但我认为这是你能做的最好的事情了。
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.
正如乔恩所说,我不认为有任何方法可以默认执行您想要的操作。但真正的问题是:你真的需要这样做吗?毕竟,这样做只会获得几个字节。值得“嘴里有难闻的味道”吗?
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?"