Search code examples
c#.netlocalizationglobalizationdatetime-format

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


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

Solution

  • 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.