gpt4 book ai didi

c# - 使用 DateTime.ToString ("tt"时,Windows 10 中的时间输出(AM/PM)发生了变化)

转载 作者:可可西里 更新时间:2023-11-01 07:58:24 25 4
gpt4 key购买 nike

我最近升级到 Windows 10 - 现在我发现在使用“tt”格式说明符时日期的输出发生了一些意想不到的变化。

下面是一些演示问题的代码:

using System.IO;
using System;
using System.Globalization;
using System.Threading.Tasks;

class Program
{
static void Main()
{
var cultures = new string[] {null, "en-NZ", "en-US", "en-AU", "en-GB"};

foreach (var culture in cultures) {
if (culture != null) {
var c = CultureInfo.GetCultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = c;
}

DateTime dt = new DateTime(2015, 1, 2, 3, 4, 5, DateTimeKind.Utc);

Console.WriteLine("selection: {0} CurrentThread.CurrentCulture.Name: {1} CurrentThread.CurrentUICulture.Name: {2} Value: {3}",
culture ?? "ambient",
System.Threading.Thread.CurrentThread.CurrentCulture.Name,
System.Threading.Thread.CurrentThread.CurrentUICulture.Name,
dt.ToString("hhh:mm tt"));
}
}
}

以前版本的 windows 中的输出是:

selection: ambient CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-NZ Value: 03:04 a.m.
selection: en-NZ CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-NZ Value: 03:04 a.m.
selection: en-US CurrentThread.CurrentCulture.Name: en-US CurrentThread.CurrentUICulture.Name: en-US Value: 03:04 AM
selection: en-AU CurrentThread.CurrentCulture.Name: en-AU CurrentThread.CurrentUICulture.Name: en-AU Value: 03:04 AM
selection: en-GB CurrentThread.CurrentCulture.Name: en-GB CurrentThread.CurrentUICulture.Name: en-GB Value: 03:04 am

在 Windows 10 中:

selection: ambient (windows 10) CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-US  Value: 03:04 a.m.
selection: en-NZ CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-NZ Value: 03:04 AM
selection: en-US CurrentThread.CurrentCulture.Name: en-US CurrentThread.CurrentUICulture.Name: en-US Value: 03:04 AM
selection: en-AU CurrentThread.CurrentCulture.Name: en-AU CurrentThread.CurrentUICulture.Name: en-AU Value: 03:04 AM
selection: en-GB CurrentThread.CurrentCulture.Name: en-GB CurrentThread.CurrentUICulture.Name: en-GB Value: 03:04 AM

在这两种情况下,这段代码都是针对 .Net Framework 4.5 在 Visual Studio 2013 中编译的

有谁知道行为发生变化的原因 - 以及为什么在 Windows 10 中似乎在线程上设置任何区域性会专门更改 AM/PM 的输出以格式化为“AM”/“PM”,而不是通常输出的内容那种文化?

最佳答案

您可能需要查看“文化数据不应该被认为是稳定的”http://blogs.msdn.com/b/shawnste/archive/2005/04/05/405694.aspx

一点是,我们开始为许多语言环境利用 CLDR(通用语言环境数据存储库,http://cldr.unicode.org),以更好地与行业标准保持一致。您可能已经注意到,我们现在有很多其他语言环境的数据。

关于c# - 使用 DateTime.ToString ("tt"时,Windows 10 中的时间输出(AM/PM)发生了变化),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31888839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com