C# TimeSeparator, differenze legate al server

giovedì 31 gennaio 2013 - 11.29
Tag Elenco Tags  C#  |  .NET 3.5

volperubbia Profilo | Senior Member

Ciao a tutti,
pubblicando la mia applicazione web ASP.NET MVC 3.5 su due server differenti, ho notato differenze di visualizzazione della data ora, quando l'italiano è la lingua corrente. Probabilmente si prende le impostazioni internazionali dal server.

Esempi:
<%= DateTime.Now.ToString() %>
<%= DateTime.Now.ToString(System.Threading.Thread.CurrentThread.CurrentCulture) %>
<%= String.Format("{0:G}", DateTime.Now) %>

Su un server mi mette i ":" come TimeSeparator, sull'altro il ".".

Ho provato nell'Application_AuthenticateRequest con:
if (System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName == "it") {
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.TimeSeparator = ":";
System.Threading.Thread.CurrentThread.CurrentCultureUI.DateTimeFormat.TimeSeparator = ":";
};
ma non ottengo cambiamenti.

Qualche idea su come uniformare il comportamento indipendentemente dal server che ospita l'applicazione?

Grazie per l'attenzione,
Davide

andrestu Profilo | Expert

prova a inserire questo nel web.config

<system.web>
....
<globalization culture="it-IT" uiCulture="it-IT"/>
....
</system.web>


Andrea Restucci - Web Developer

volperubbia Profilo | Senior Member

Ciao Andrea,
no serve ... ho ricontrollato e basta impostare su Application_AuthenticateRequest:

if (System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName == "it") {
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.LongTimePattern = "HH:mm:ss";
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern = "HH:mm";
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.TimeSeparator = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.TimeSeparator = ":";
};

Grazie comunque,
Davide
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5