c# - DateTimeFormatInfo.MonthDayPattern 在 Windows Server 2012 中已更改 - 如何将其恢复?

标签 c# .net cultureinfo

在澳大利亚,一位客户一直在输入 “1/5” 作为 5 月第一天的快捷方式。我们刚刚从 Windows Server 2008 迁移到 Windows Server 2012。

在 LinqPad 中使用以下代码:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-au", false);
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern.Dump();
DateTime.Parse("1/5").Dump();

在 Windows Server 2008 上:

dd MMMM

1/05/2016 12:00:00 AM

在 Windows Server 2012 R2 上:

MMMM d

5/01/2016 12:00:00 AM

问题:

  1. 为什么 MonthDayPattern 发生了变化?澳大利亚人总是先有日,后有月
  2. 这可以在 Windows Server UI 的什么地方设置? UI 仅公开长格式和短格式,不公开月和日格式
  3. 如果整个系统都可能发生 DateTime.Parse(例如,模型绑定(bind)、验证等),我该如何用最少的更改解决我的应用程序中的问题<

最佳答案

我可以在 Windows Server 2012 上复制该问题。如果您添加...

System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.Dump();  

你会看到它返回...

d/MM/yyyy

只有 MonthDayPattern 似乎不正确。这可能是一个错误。我会在 https://connect.microsoft.com/ 上记录问题.

与此同时,您可以简单地设置 MonthDayPattern....

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-au", false);
System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.Dump();
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern.Dump();
DateTime.Parse("1/5").Dump();
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern = "d MMMM";
DateTime.Parse("1/5").Dump();

在 Windows Server 2012 R2 上:

d/MM/yyyy

MMMM d

5/01/2016 12:00:00 AM

1/05/2016 12:00:00 AM

关于c# - DateTimeFormatInfo.MonthDayPattern 在 Windows Server 2012 中已更改 - 如何将其恢复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38235845/

相关文章:

c# - 除了ICMP(Ping)以外,如何从LAN控制计算机是否处于打开状态?

c# - 使 Javascript 代码在 Page Start 上运行

c# - 如何将 int 数组转换为 int?

.net - Entity Framework 和 .NET 4.0 的 LINQ to SQL 之间有什么区别?

c# - 如何在 Expression Blend 2013 中获取 WPF 和 Windows Phone 模板?

c# - 处置 StringBuilder 对象

c# - 对于某些文化,解析包含毫秒的 DateTime 失败。为什么?

c# - .NET (3.5) 使用点而不是冒号作为 IT 文化的 TimeSeparator 来格式化时间?

c# - 为国家、语言组合创建自定义 CultureInfo

c# - MVC 3 中的下拉列表