(来自相同文化的)CultureInfo实例根据操作系统而变化 [英] Instances of CultureInfo (from same culture) changing based on OS

查看:66
本文介绍了(来自相同文化的)CultureInfo实例根据操作系统而变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,上面写着这样的日期:

I've a web site which writes a date like this:

CultureInfo cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => string.Equals(c.TwoLetterISOLanguageName, MvcApplication.Language));
return string.Concat(date.Day, ".", cultureInfo.DateTimeFormat.GetAbbreviatedMonthName(date.Month));

在我的PC(Windows 7,Service Pack 1,西班牙语)和服务器(Windows Server)中2012,英语文化) MvcApplication.Language es ,因此我从列表中得到的文化是: es-ES

In both my PC (Windows 7, Service Pack 1, Spanish culture) and the server (Windows Server 2012, English Culture) the MvcApplication.Language is es so the culture I get from the list is: es-ES.

我希望它们都写相同的字符串(它们具有不同的文化,但我不是使用 CurrentCulture )。但是结果是我的PC中的 abr 和服务器中的 Abr。

I'd expect they both write the same string (they have different cultures, but I'm not using CurrentCulture). However the results are abr in my PC and Abr. in the server.

我已经尝试使用MvcApplication.Language 隔离nofollow> LinqPAD ,但还是不一样。我已经打印了 AbbreviatedDayNames AbbreviatedMonthNames 的数组,它们在每台计算机上都不同。

I've tried this isolated from MvcApplication.Language using the LinqPAD but it is still different. I've printed the arrays of AbbreviatedDayNames and AbbreviatedMonthNames and they are different in each computer.

我做错什么了吗,或者这是预期的行为?如何使它完全独立于Windows /用户文化?

Am I doing something wrong or this is the expected behavior? How can I do to make it completely independent from Windows / User Culture?

推荐答案

您可以在此链接,在某些Windows版本上,区域性信息可能会有所不同。 / p>

A you can see in this link from MSDN, culture info can be different on some windows versions.


请记住,区域性名称和标识符仅表示可以在特定计算机上找到的区域性的子集。 Windows版本或Service Pack可以更改可用的区域性。应用程序使用CultureAndRegionInfoBuilder类添加自定义区域性。用户使用Microsoft Locale Builder工具添加自己的自定义区域性。 Microsoft Locale Builder是使用CultureAndRegionInfoBuilder类以托管代码编写的。

Remember that the culture names and identifiers represent only a subset of cultures that can be found on a particular computer. Windows versions or service packs can change the available cultures. Applications add custom cultures using the CultureAndRegionInfoBuilder class. Users add their own custom cultures using the Microsoft Locale Builder tool. Microsoft Locale Builder is written in managed code using the CultureAndRegionInfoBuilder class.

如果您希望某些格式是静态的,则可以构建自己的格式CultureInfo对象并自定义其行为,设置您自己的日期时间格式,例如

If you want some format to be static, you can build your own CultureInfo object and customize the behaviour of it, setting your own Date Time format, as an example

这篇关于(来自相同文化的)CultureInfo实例根据操作系统而变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆