Instances of CultureInfo (from same culture) changing based on OS

六眼飞鱼酱① 提交于 2019-12-10 15:29:10

问题


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));

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.

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.

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.

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


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/16240525/instances-of-cultureinfo-from-same-culture-changing-based-on-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!