2010-03-18 9 views
5

In unserer web.config verwende ich das folgende Tag, um die Sprache der Benutzeroberfläche einer ASP.NET-Website zu bestimmen.Festlegen eines Datumsformats im Globalisierungs-Tag web.config von ASP.NET?

<globalization 
    enableClientBasedCulture="true"   
    culture="auto:en-GB" 
    uiCulture="auto:en"/> 

Dies funktioniert wie erwartet: Client wo Anfrage eine spezifische Lokalisation es erhalten, alle anderen suchen ist glücklich an den en-GB-Einstellungen.

Aufgrund der Firmenpolitik muss ich das Datumsformat für alle auf das ISO 8601 Standardformat (JJJJ-MM-TT) ändern. Ist dies an einer zentralen Stelle in der web.config möglich oder muss ich das in jedem Fall manuell ändern?

Zusatz: Wäre es möglich, dieses Datumsformat zu erhalten, wenn die Schnittstelle auf Englisch beschränkt wird?

Antwort

6

Sie sollten Ihre eigene Kultur build von CultureAndRegionInfoBuilder mit

class Program 
     { 
      static void Main(string[] args) 
      { 
       CultureInfo ci; 
       CultureAndRegionInfoBuilder cib = null; 
       try 
       { 
        // Create a CultureAndRegionInfoBuilder object named "x-en-GB". 
        Console.WriteLine("Create and explore the CultureAndRegionInfoBuilder...\n"); 
        cib = new CultureAndRegionInfoBuilder(
         "x-en-GB", CultureAndRegionModifiers.None); 

        // Populate the new CultureAndRegionInfoBuilder object with culture information. 
        ci = new CultureInfo("en-GB"); 
        ci.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"; 
        //ci.DateTimeFormat.FullDateTimePattern = "yyyy-MM-dd"; 
        //ci.DateTimeFormat.LongDatePattern = "yyyy-MM-dd"; 

//... 
        //... 
        cib.LoadDataFromCultureInfo(ci); 




        // Populate the new CultureAndRegionInfoBuilder object with region information. 
        RegionInfo ri = new RegionInfo("GB"); 
        cib.LoadDataFromRegionInfo(ri); 

        Console.WriteLine("Register the custom culture..."); 
        cib.Register(); 



       } 
       catch (Exception e) 
       { 
        Console.WriteLine(e); 
       } 

       Console.WriteLine("Create and explore the custom culture...\n"); 
       ci = new CultureInfo("x-en-GB"); 

       //Thread.CurrentThread.CurrentCulture = ci; 
       //Thread.CurrentThread.CurrentUICulture = ci; 

       Console.WriteLine(DateTime.Now.ToString(ci)); 

       Console.ReadLine(); 
      } 
     } 
2

Wenn das Format in allen Kulturen gleich sein muss, müssen Sie das DateTimeFormat immer dann festlegen, wenn Sie ein CultureInfo Objekt instanziieren.

Es gibt keine globale Konfigurationsoption dafür.