2016-07-07 21 views
6

在澳大利亞,客戶輸入"1/5"作爲5月第一天的快捷方式。我們剛剛從Windows Server 2008移動到Windows Server 2012DateTimeFormatInfo.MonthDayPattern在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 201上2 R2:

MMMM d

2016年5月1日12:00:00 AM

問題:

  1. 爲什麼在MonthDayPattern改變?澳大利亞人總是有第一天,然後月
  2. 哪裏可以在Windows服務器用戶界面中設置?用戶界面只顯示長和短格式,而不是月份和日格式
  3. 如何在我的應用程序中用最少量的更改修復問題,因爲可能有DateTime.Parse發生在整個系統中(例如,模型綁定,校驗等)
+0

您正在使用哪個版本的Linqpad? – Mick

+0

4,我們在服務器上沒有.Net 4.6,所以不能使用5 – user917170

回答

2

我可以複製的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/01 12:00:00 AM

2016/1/05 12:00:00 AM

+0

我認爲你是正確的,最簡單的解決方案是在線程上設置自己的格式。仍然沒有解釋爲什麼問題存在,所以我會提出一個問題,連接.... – user917170

+0

嘿@ user917170 - 你有沒有聽說過任何微軟關於這個?我剛剛遇到了一個非常類似的問題。我的服務器從dd MMMM切換到d MMMM,這使得這個bug更加隨機和混亂...... – kirbatious

相關問題