Pregunta

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
¿Fue útil?

Solución

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top