Domanda

Oracle returns datetime format according by browser culture that used by client.For instance while retrieving month on sysdate in oracle, if my browser culture is en-US return January, if tr-TR is return Ocak but i want to appear it only Turkish.I applied a couple changes on my code as follow but i am getting error some cases.

DateTime.ParseExact("Ocak", "MMMM", CultureInfo.CurrentUICulture).ToString("MMMM", new CultureInfo("tr-TR"));

I can get error according by above sample.Because CultureInfo.CurrentUICulture and browser culture don't be same.January in not equal each Turkish month value.

È stato utile?

Soluzione

You can check your CurrentUICulture which is InvariantCulture (based on en-US) or not like;

if(CultureInfo.CurrentUICulture == CultureInfo.InvariantCulture)
{
     var month = DateTime.ParseExact("January", "MMMM", CultureInfo.InvariantCulture);
     Console.WriteLine(month.ToString("MMMM", new CultureInfo("tr-TR"))); //ocak
}
else if(CultureInfo.CurrentUICulture == new CultureInfo("tr-TR"))
{
     var month = DateTime.ParseExact("Ocak", "MMMM", new CultureInfo("tr-TR"));
     Console.WriteLine(month); //ocak
}
else
{
     //
}

Altri suggerimenti

Add globalization tag in web.config

<globalization uiCulture="es" culture="es-MX" />

Read more here

Add <globalization /> tag in Web.config. Check this LINK, this will help you.

TO_CHAR (sysdate, 'Month', 'NLS_DATE_LANGUAGE = TURKISH')

You can use this code inside sql

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top