我有过以后的代码,但现在已经转移到新服务器并且已停止工作,因为27-11-2013未被识别为有效的日期时间。它使用所以我不想进行任何代码更改,因为显然需要进行服务器配置更改。但是哪个区域/区域设置会影响DateTime.Parse?我已经尝试过改变它们中的很多但是没有一个已经有效。
哦,我不想/不能使用ParseExact ......
答案 0 :(得分:3)
DateTime.Parse
会使用当前文化。
DateTime dt= DateTime.Parse("27-11-2013", new CultureInfo("en-gb"));
答案 1 :(得分:1)
试试这个:
CultureInfo customCulture = new CultureInfo("en-GB");
DateTime myDateTime = DateTime.Parse("27-11-2013", customCulture.DateTimeFormat);
答案 2 :(得分:0)
您可以在web.config中执行此操作,如下所示
<globalization culture="en-GB" uiCulture="en-GB"/>