在Windows 10中,使用DateTime.ToString(“ tt”)时,时间(AM / PM)的输出已更改 [英] Output of times (AM/PM) changed in Windows 10 when using DateTime.ToString("tt")

查看:147
本文介绍了在Windows 10中,使用DateTime.ToString(“ tt”)时,时间(AM / PM)的输出已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到Windows 10-使用 tt格式说明符时,我现在看到日期输出中的一些相当意外的变化。

I recently upgraded to windows 10 - and I'm now seeing some rather unexpected changes in the output of a date when using the "tt" format specifier.

下面的代码演示了这个问题:

Here's some code that demonstrates the issue:

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

以前版本的输出窗口是:

The output in previous versions of windows was:

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中:

And in 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中编译的。

In both cases this code was compile win Visual Studio 2013 targeting .Net Framework 4.5

有人知道为什么行为已更改-以及为什么在Windows 10中会出现这种情况吗?线程上的任何区域性都专门将AM / PM的输出更改为 AM / PM格式,而不是通常为该区域性输出什么?

Does anyone know why the behavior has changed - and why in windows 10 it appears setting any culture on a thread specifically changes the output of AM/PM to be formatted as "AM" / "PM" not what is normally outputted for that culture?

推荐答案

您可能希望查看不应认为文化数据稳定 http://blogs.msdn.com/b/shawnste/archive/2005/04/05/405694.aspx

You may want to look at "Culture Data Shouldn't Be Considered Stable" http://blogs.msdn.com/b/shawnste/archive/2005/04/05/405694.aspx

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

One bit is that we started leveraging CLDR (Common Locale Data Repository, http://cldr.unicode.org) for many locales to better align with the industry standards. You may have noticed that there are quite a few additional locales we now have data for.

这篇关于在Windows 10中,使用DateTime.ToString(“ tt”)时,时间(AM / PM)的输出已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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