简体   繁体   English

CultureInfo数据来自哪里?

[英]Where does CultureInfo data come from?

When I create a culture info object for en-CA ( new CultureInfo("en-CA") ) I'm getting a different ShortDatePattern in my production environment than in my development environment. 当我为en-CA创建文化信息对象( new CultureInfo("en-CA") )时,在生产环境中和开发环境中得到的ShortDatePattern不同。

I don't have access to the production server then I'm just assuming that the information that fills the object comes from regional settings. 我没有访问生产服务器的权限,那么我只是假设填充对象的信息来自区域设置。

I tried to change my development regional settings to have a different ShortDatePattern for en-CA but I'm still getting "MM/dd/yyyy" instead of "yyyy-MM-dd" 我尝试将开发区域设置更改为针对en-CA具有不同的ShortDatePattern ,但我仍收到"MM/dd/yyyy"而不是"yyyy-MM-dd"

Where does this configuration come from and what could be the difference between my local environment and the production environment that is returning a different ShortDatePattern for the same CultureInfo? 此配置来自何处?我的本地环境与为同一CultureInfo返回不同的ShortDatePattern的生产环境之间可能有什么区别?

Code: 码:

var someDate = DateTime.now;
var cultureInfo = new CultureInfo("en-CA");
var formatedDate = someDate.ToString(cultureInfo.DateTimeFormat.ShortDatePattern);

It's the machine culture, in order to force a culture on your app you have to add it in the web config or the app config 这是机器文化,要在您的应用上强制使用文化,您必须将其添加到Web配置或应用配置中

To set the UI culture and culture for all pages, add a globalization section to the Web.config file, and then set the uiculture and culture attributes, as shown in the following example: 要为所有页面设置UI文化,请在Web.config文件中添加一个全球化部分,然后设置uiculture和文化属性,如以下示例所示:

<globalization uiCulture="en-CA" culture="en-CA" />

here is the MSDN Source 这是MSDN来源

That's because the CultureInfo constructor uses the customised user configuration by default. 这是因为默认情况下CultureInfo构造函数使用自定义的用户配置。 Use the constructor that takes an extra bool parameter useUserOverride and pass false . 使用需要额外的bool参数useUserOverride的构造函数,并传递false

From the documentation 文档中

useUserOverride useUserOverride

A Boolean that denotes whether to use the user-selected culture settings (true) or the default culture settings (false). 一个布尔值,指示是使用用户选择的区域性设置(true)还是使用默认区域性设置(false)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM