How to Change DateTimeFormatInfo.CurrentInfo Collection of Abbreviated DayNames

How to change the DateTimeFormatInfo.CurrentInfo Collection of the AbbreviatedDayNames. I want to use mine as Tues instead of Tue And when I use ToString("ddd") , I want to see Tue

Is this possible in C #?

+6
source share
3 answers

You can do it this way

 CultureInfo cinfo = CultureInfo.CreateSpecificCulture("en-EN"); cinfo.DateTimeFormat.AbbreviatedDayNames = new string[]{"Suns","Mon","Tues", "Weds","Thursday","Fries","Sats"}; 

Now designate it as your current culture, and you should be good to go

+6
source

Create a new custom CultureInfo file and then fill in your values

  var dt = DateTime.Now; CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); // second parameter is useUserOverride Console.WriteLine(dt.ToString("ddd", ci)); ci.DateTimeFormat.AbbreviatedDayNames = new string[] { "D1", "D2", "D3", "D4", "D5", "D6", "D7" }; Console.WriteLine(dt.ToString("ddd", ci)); 
+2
source

According to this msdn link, the AbbreviatedDayNames collection is read / written, which means you can overwrite it. However, since it depends on the culture, it will only work when the culture is installed and used (read-only invariant).

You may be able to create a new culture for this, but I believe this is OTT.

+1
source

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


All Articles