Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change month names that are returned from ToString("MMMM") to own names

With following code I get the following result in de-CH culture:

var dateFormat = new DateTime(2016, 10, 12).ToString("MMMM");
//Oktober

Though what I really want is "Oktobär" because I am translating into a dialect.

Can I override which month names are returned in de-CH culture? The names that it returns for other cultures should stay the same.

like image 520
maracuja-juice Avatar asked Oct 12 '16 06:10

maracuja-juice


1 Answers

CultureInfo myCIclone = new CultureInfo("de-CH");

myCIclone.DateTimeFormat.MonthNames = new string[]
{"1","2","3","4","5","6","7","8","9","Oktobär","11","12", "13"};

var dateFormat = new DateTime(2016, 10, 12).ToString("MMMM", myCIclone);

You can override the MonthNames like John Skeet mentioned, for specific culture info.

like image 176
mybirthname Avatar answered Oct 15 '22 20:10

mybirthname