maracuja-juice
maracuja-juice

Reputation: 1042

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.

Upvotes: 7

Views: 1625

Answers (2)

mybirthname
mybirthname

Reputation: 18137

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.

Upvotes: 6

Power Star
Power Star

Reputation: 1894

This may be help full to you. You need to override the default value.

//Declare Culture Info with your goblaization name.
CultureInfo culture = new CultureInfo("de-CH");

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

//Assign it in string.
string date= new DateTime(2016, 10, 12).ToString("MMMM", culture);

Upvotes: 0

Related Questions