【问题标题】:DateTimeFormatInfo.MonthDayPattern Has Changed in Windows Server 2012 - How Can I set it back?Windows Server 2012 中的 DateTimeFormatInfo.MonthDayPattern 已更改 - 如何将其重新设置?
【发布时间】:2016-07-07 00:20:44
【问题描述】:

在澳大利亚,一位客户在 5 月的第一天输入了 "1/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

2016 年 1 月 5 日上午 12:00:00

在 Windows Server 2012 R2 上:

MMMM d

2016 年 5 月 1 日上午 12:00:00

问题:

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

【问题讨论】:

  • 您使用的是哪个版本的 Linqpad?
  • 4,我们服务器上没有.Net 4.6,所以不能使用5

标签: c# .net cultureinfo


【解决方案1】:

我可以在 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

2016 年 5 月 1 日上午 12:00:00

2016 年 1 月 5 日上午 12:00:00

【讨论】:

  • 我认为你是对的,最简单的解决方案是在线程上自己设置格式。仍然没有解释为什么存在问题,所以我会在连接上提出一个问题....
  • 嘿@user917170 - 你有没有听过微软关于这方面的任何消息?我刚刚遇到了一个非常相似的问题。我的服务器从 dd MMMM 切换到 d MMMM,这使得这个 bug 更加随机和混乱......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多