2012-05-17 54 views
0

即使我已經CurrentCulture在DateTime.TryParse()C#MVC3 Web應用程序中被忽略?

<globalization uiCulture="en" culture="en-GB" requestEncoding="utf-8" /> 

在web.config中 DateTime.TryParse,沒有通過的CultureInfo,無視我目前的文化。

應用程序是一個C#MVC3 web應用程序。

有沒有解決方案。

+1

MSDN說的TryParse應該使用當前文化信息。你能給我們一個不正確的解析的例子嗎?你也可以使用TryParseExact - http://msdn.microsoft.com/en-gb/library/system.datetime.tryparseexact.aspx,如果它可以成爲你的解決方案。 – Smileek

+0

現在我明白,MVC應用程序的web.config不適用於子aspx Web應用程序。一旦我修改了aspx應用程序文件夾中的web.config,它工作正常。感謝您的答覆。 – Rafi

回答

0

@Smileek正確的,但你總是可以嘗試這樣的事情

DateTime dateResult; 
dateString = "03/01/2009 10:00 AM"; 
culture = CultureInfo.CreateSpecificCulture("en-US"); 
styles = DateTimeStyles.None; 
DateTime.TryParse(dateString, culture, styles, out dateResult);