Jag försöker skiva ut dagens namn och datum på en sida med det verkar inte slå igenom men när jag använder samma kod (se nedan) i en .aspx-sida på samma site som inte har med EPiServer att göra (ärver alltså inte från TemplatePage) så fungerar koden utmärkt.
Jag vill allså att när man surfar med t.ex epslaguage=SE att dagens namn skall stå på svenska osv.
Någon som vet varför det inte blir rätt i EPiServer
//Stefan
System.Globalization.CultureInfo info;
switch(LanguageID){
case 1:
info = new System.Globalization.CultureInfo("en-GB", false);
break;
case 2:
info = new System.Globalization.CultureInfo("sv-SE", false);
break;
default:
info = new System.Globalization.CultureInfo("it-IT", false);
break;
}
System.Globalization.Calendar calendar = info.Calendar;
string sDate = "";
try {
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
int day = DateTime.Now.Day;
DateTime dateTime = new DateTime(year, month, day, calendar);
sDate = dateTime.ToString("dddd d MMMM yyyy");
}catch{}
welcomedate.InnerHtml = sDate;
Hi
Worked for me when I was using UserControlBase... so move your code into a user control and try that.
I havent tried in a TemplatePage but at least its not unworkable :)
/John
I tried it in TemplatePage and it worked too
Is the problem that the culture is defaulting to EPiServer's settings (in settings) and not choosing the other languages from the switch statement?
If so, change languages in settings and see if the dates come out according to EPiServers settings... If they do then its probably EPiServer code overriding your code at some point -
but if you try:
sDate = dateTime.ToString("dddd d MMMM yyyy",info.DateTimeFormat);
it should work fine :)
System.Globalization.CultureInfo info; switch(LanguageID){ case 1: info = new System.Globalization.CultureInfo("en-GB", false); break; case 2: info = new System.Globalization.CultureInfo("sv-SE", false); break; default: info = new System.Globalization.CultureInfo("it-IT", false); break; } System.Globalization.Calendar calendar = info.Calendar; string sDate = ""; try { int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; DateTime dateTime = new DateTime(year, month, day, calendar); sDate = dateTime.ToString("dddd d MMMM yyyy"); }catch{} welcomedate.InnerHtml = sDate;