How does the .NET process get culture information?

I have a Windows service (C #, .NET 2.0) running on Windows Server 2003 R2. On one server System.Threading.Thread.CurrentThread.CurrentCulture- {en-AU} and in another {en-US}. This caused a difference when calling ToString () on a DateTime object . I want culture to be {en-AU}.

I checked the "Regional and Language Settings". On both servers, the "Regional Settings" tab displays "English (Asutralia)." But the Advanced tab displays "English (USA)" for one and "English (Australia)" for the other. Therefore, this should make a difference. Although I want to know why the “Advanced” tab says “non-Unicode language version”, I thought that .NET processes are Unicode and should not be affected by this.

How does the .NET runtime determine which culture to use? Any detailed link would be helpful.

+3
source share
3 answers

, Thread.CurrentThread.CurrentCulture " ", . "" .

, ( ), LocalSystem, , . , , Windows.

, :

  • CurrentCulture . , , , , CurrentCulture, .

  • ( ) , . , .

  • , , DateTime.ToString(), , AU ToString():

    DateTime.ToString(new CultureInfo("en-AU"))
    

    , :

    public static string ToAUString(this DateTime dateTime)
    {
        return dateTime.ToString(new CultureInfo("en-AU"));
    }
    

    DateTime.ToAUString(), .

+8

:

System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo( "en-US" )

.

+3

MSDN CultureInfo , :

, Windows, . , , . , .

UseUserOverride , Windows, CultureInfo , DateTimeFormatInfo, DateTimeFormat, NumberFormatInfo, NumberFormat. , CultureInfo, , , undefined.

, .

+1

Source: https://habr.com/ru/post/1723046/


All Articles