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

2019-06-18 05:40发布

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

2条回答
beautiful°
2楼-- · 2019-06-18 05:55

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.

查看更多
Animai°情兽
3楼-- · 2019-06-18 06:03

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

查看更多
登录 后发表回答