Try our conversational search powered by Generative AI!

Cultureinfo

Vote:
 
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;
#12188
Dec 13, 2004 11:45
Vote:
 
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
#13814
Dec 13, 2004 13:58
Vote:
 
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 :)
#13815
Dec 13, 2004 14:17
Vote:
 
I might also suggest EPiServer.Personalization.PersonalizedData.Current.Language as something to explore perhaps. /John
#13816
Dec 13, 2004 14:34
Vote:
 
Thanx alot John! All I had to do was to add info.DateTimeFormat into the ToString() just as you wrote.. /Stefan
#13817
Dec 13, 2004 16:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.