CultureInfo.GetCultures returns 特定文化的 DateTimeSettings 与按名称或 LCID 使用 GetCultureInfo 时不同

CultureInfo.GetCultures returns different DateTimeSettings for specific culture than when using GetCultureInfo by Name or LCID

首先,我编辑区域设置并将区域设置 nl-BE 的日期格式更改为使用 yyyy-MM-dd

然后在我的 ASP.NET 代码中(Windows 10 机器上的标准 .Net 4.6.1)我 运行 这个代码:

CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures)

结果是一个包含文化的列表。当我专门查看我更改的语言环境 (nl-BE) 时,我得到以下结果:

这与我在 windows 设置中指定的相同,如上图所示,看起来不错。

如果我在同一应用程序中按名称或 LCID 搜索此特定区域设置,则不会显示此自定义设置:

有人可以向我解释为什么两者之间存在差异吗?

我是否可以使用另一个密钥来确保获得相同的结果?

CultureInfo class 的构造函数有一个 Boolean 参数 useUserOverride 指定是否应用您为用户配置文件设置的(区域)设置 (转到注册表中的 HKEY_CURRENT_USER\Control Panel\International

public CultureInfo(int culture) : this(culture, true) {}

public CultureInfo(int culture, bool useUserOverride) 
{
   // ...
}

useUserOverride:
A Boolean that denotes whether to use the user-selected culture settings (true) or the default culture settings (false).


CultureInfo.GetCultures(CultureTypes types) (via CultureData.GetCultures(CultureTypes types)) 使用 true 创建实例(通过构造函数的默认值)。

cultures[i] = new CultureInfo(cultureNames[i]);

所以这些文化有你的改变。


GetCultureInfo(int culture) instantiates a CultureInfo (using GetCurrentInfoHelper) 将 false 传递给 userUserOverride:

retval = new CultureInfo(lcid, false);

这会导致返回的 CultureInfo 没有您的更改。