【问题标题】:CultureInfo is not consistent between windows versionsCultureInfo 在 windows 版本之间不一致
【发布时间】:2016-01-12 23:06:32
【问题描述】:

有没有人注意到在不同版本的 Windows 上 CultureInfo 格式会导致不同的模式?

Windows 7 创建 dddd、MMMM dd、YYYY

示例输出: Windows 7

Windows 10 和 Windows Server 2012 都创建了 dddd、MMMM d、YYYY

示例输出: Windows 10 & Server 2012 R2

我从MSDN site on DateTime 获得了这个样本。修改为检查前导零。

public class Sample
{
    public static void Main()
    {
        string msg1 = "The date and time patterns are defined in the DateTimeFormatInfo \n" +
                      "object associated with the current thread culture.\n";

        // Initialize a DateTime object.
        Console.WriteLine("Initialize the DateTime object to May 06, 2001 3:02:15 AM.\n");
        DateTime myDateTime = new System.DateTime(2001, 5, 6, 3, 2, 15);

        // Identify the source of the date and time patterns.
        Console.WriteLine(msg1);

        // Display the name of the current culture.
        CultureInfo ci = CultureInfo.GetCultureInfo("en-us");
        Console.WriteLine("Current culture: \"{0}\"\n", ci.Name);

        // Display the long date pattern and string.
        Console.WriteLine("Long date pattern: \"{0}\"", ci.DateTimeFormat.LongDatePattern);
        Console.WriteLine("Long date string:  \"{0}\"\n", myDateTime.ToLongDateString());

        // Display the long time pattern and string.
        Console.WriteLine("Long time pattern: \"{0}\"", ci.DateTimeFormat.LongTimePattern);
        Console.WriteLine("Long time string:  \"{0}\"\n", myDateTime.ToLongTimeString());

        // Display the short date pattern and string.
        Console.WriteLine("Short date pattern: \"{0}\"", ci.DateTimeFormat.ShortDatePattern);
        Console.WriteLine("Short date string:  \"{0}\"\n", myDateTime.ToShortDateString());

        // Display the short time pattern and string.
        Console.WriteLine("Short time pattern: \"{0}\"", ci.DateTimeFormat.ShortTimePattern);
        Console.WriteLine("Short time string:  \"{0}\"\n", myDateTime.ToShortTimeString());


        Console.ReadLine();
    }
}

【问题讨论】:

  • 来自 CultureInfo 的文档:“除了不变的文化,文化数据是动态的。即使对于预定义的文化也是如此。例如,国家或地区采用新的货币,改变他们的单词拼写, 或更改其首选日历,并且文化定义会更改以跟踪此情况。自定义文化如有更改,恕不另行通知,并且任何特定文化可能会被自定义替换文化覆盖。此外,如下所述,个人用户可以覆盖文化偏好. 应用程序应始终在运行时获取文化数据。”
  • @MikeZboray,我惊讶地发现 en-NZ 将 TShortTimeStrting 的模式 'tt' 从 'a.m./p.m.'到“上午/下午”,我花了很多时间查看 .Net 公告和文档,以找出何时将该更改引入 Windows 10 和 Windows Server 2016(或更早版本的 Windows Server)的任何迹象。但确实,they are subject to change without notice.

标签: c# .net windows cultureinfo windows-server-2012-r2


【解决方案1】:

此外,Windows 10 上还有更多 CultureInfo 可用。我希望这将与 Windows Server 2016 保持一致,并且最好通过 WU 推送到所有版本。

例如; Windows 10 支持 247 regions,而 Windows 2012R2 仅支持 142 regions。

CultureInfo 对象划分区域:

Windows 10

Windows 2012R2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    相关资源
    最近更新 更多