use*_*170 6 .net c# cultureinfo
在澳大利亚,一位客户已成为"1/5"5月1日的捷径.我们刚刚从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();
Run Code Online (Sandbox Code Playgroud)
在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
问题:
DateTime.Parse到整个系统可能发生的一切(例如,模型绑定,验证等),如何在应用程序中以最少的更改来解决问题 我可以在 Windows Server 2012 上复制该问题。如果您添加...
System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.Dump();
Run Code Online (Sandbox Code Playgroud)
你会看到它返回...
日/月/年
只有 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();
Run Code Online (Sandbox Code Playgroud)
在 Windows Server 2012 R2 上:
日/月/年
MMMM d
2016 年 5 月 1 日 12:00:00 上午
2016 年 1 月 5 日 12:00:00 上午