Get a culture related date with a 2 digit year in C #

I am updating some code that formats a date into a string using "MM / dd / yy". I need her to be culturally aware, but I want to keep a two-digit year in order to keep the date shorter. Below I came up with, but is there a better way?

string dateFormat = culture_Info.DateTimeFormat.ShortDatePattern.Replace("yyyy", "yy"); 
+6
source share
2 answers

I don't know anything, no (and I pretty much considered formatting). What you have, obviously, still leaves an unpleasant taste in your mouth, but I think this is the best you can do.

+5
source

As John says, I don’t think that by default you can do what you want. But the real question is: do you really need to do this? In the end, you only type a couple of bytes. Is there a "bad taste in your mouth?"

0
source

Source: https://habr.com/ru/post/906883/


All Articles