Get culture-specific date with 2 digit year in C#

天大地大妈咪最大 提交于 2019-12-10 13:32:36

问题


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

回答1:


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.




回答2:


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?"



来源:https://stackoverflow.com/questions/9006806/get-culture-specific-date-with-2-digit-year-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!