Question

GetMonthName's virtual ToString method that inside DateTimeFormatInfo class is not working properly.I 'm adding culture code to CultureInfo but it is returning invariant value.

DateTimeFormatInfo d = new DateTimeFormatInfo();
d.GetMonthName(1).ToString(new CultureInfo("tr-TR")); // returns January
Était-ce utile?

La solution

GetMonthName returns a string. There is no translation that happens when you call toString on a string even if you provide a CultureInfo. What you want to do is something like this:

var trTr = new CultureInfo("tr-TR");
trTr.DateTimeFormat.GetMonthName(1);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top