为什么在不同的设备上相同文化的缩写月份会不同?

huangapple go评论75阅读模式
英文:

Why are different abbreviated months given for the same culture on different machines?

问题

在针对 .Net 6 时,在 Windows 10 上,我得到了 Sep,但在 Windows 11 上,我得到了 Sept

在每种情况下都使用了默认的 DateTimeFormatInfo.AbbreviatedMonthNames。为什么会发生这种情况?

英文:

I am getting a different month abbreviation for the same culture as a work colleague.

var x = new DateTime(2023, 9, 27);
Console.WriteLine(x.ToString("MMM", new CultureInfo("en-GB")));

When targeting .Net 6, on Windows 10 I get Sep, but on Windows 11 I get Sept.

The default DateTimeFormatInfo.AbbreviatedMonthNames are being used in each instance. Why would this happen?

答案1

得分: 1

看起来操作系统是这种行为的原因。微软的CultureInfo文档(如另一个Stack Overflow答案中提到)陈述了以下内容:

> 语言环境名称和标识符只代表了特定计算机上可以找到的语言环境的子集。Windows版本或服务包可能会更改可用的语言环境。应用程序可以使用CultureAndRegionInfoBuilder类添加自定义语言环境。用户可以使用Microsoft Locale Builder工具添加自己的自定义语言环境。Microsoft Locale Builder使用CultureAndRegionInfoBuilder类以托管代码编写。

这有点不清楚,它是否只是意味着可用的语言环境集可以增加和减少,或者语言环境的内容可以被编辑。然而,我和我的同事看到的不同的缩写月份名称暗示着操作系统可以修改内容。

这一点很重要,因为许多开发人员可能会假设在任何操作系统上给定的语言环境都是相同的。

英文:

It seems that the OS is the reason for this behaviour. The Microsoft CultureInfo docs (as mentioned in another Stack Overflow answer) state the following:

> 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 can add
> custom cultures using the CultureAndRegionInfoBuilder class. Users can
> add their own custom cultures using the Microsoft Locale Builder tool.
> Microsoft Locale Builder is written in managed code using the
> CultureAndRegionInfoBuilder class.

It's a bit unclear if this just means that the set of available cultures can be added to and subtracted from or if the content of the cultures can be edited. However, the different abbreviated month names seen by my colleague and I imply that the contents can be modified by an OS.

This is important to note as many devs might assume that a given culture would be the same on any OS.

huangapple
  • 本文由 发表于 2023年5月24日 21:59:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324360.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定