How to change DateTimeFormatInfo.CurrentInfo
AbbreviatedDayNames collection. I want to use mine, like Tues
instead of Tue
. And when I use ToString("ddd")
I want to see Tue
.
Is it possible in C#?
You may do it in this fashion
CultureInfo cinfo = CultureInfo.CreateSpecificCulture("en-EN");
cinfo.DateTimeFormat.AbbreviatedDayNames = new string[]{"Suns","Mon","Tues", "Weds","Thursday","Fries","Sats"};
Now assign this as your current culture and you should be good to go
Create new user-writeable CultureInfo and then fill 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));
According to this msdn link the AbbreviatedDayNames collection is read/write, which would imply that you could overwrite it. However as it is culture dependent, this would only work when a culture is set and used ( the invariantinfo is readonly ).
You might be able to/have to create a new culture to use for this, but I reckon that is OTT.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With