简体   繁体   English

DateTime.Parse不再识别英国格式

[英]DateTime.Parse not recognising UK formats anymore

I have code that used to work, but has now moved to a new server and has stopped working as 27-11-2013 is not being recognised as a valid datetime. 我拥有曾经可以工作的代码,但是现在已移至新服务器并已停止工作,因为2013年11月27日未被识别为有效的日期时间。 It used to so I don't want to make any code changes as there's obviously a server config change that needs to happen. 过去 ,我不想进行任何代码更改,因为显然需要进行服务器配置更改。 But which region/locale setting affects DateTime.Parse? 但是哪个区域/区域设置会影响DateTime.Parse? I've tried changing quite a number of them but not one has worked yet. 我已经尝试过更改其中的许多功能,但尚未奏效。

Oh, and I don't want to/can't use ParseExact... 哦,我不想/不能使用ParseExact ...

如果您未指定其他DateTime.Parse将使用当前区域性。

DateTime dt= DateTime.Parse("27-11-2013", new CultureInfo("en-gb"));

Try this : 尝试这个 :

CultureInfo customCulture = new CultureInfo("en-GB");
DateTime myDateTime = DateTime.Parse("27-11-2013", customCulture.DateTimeFormat);

您可以在web.config中执行以下操作

    <globalization culture="en-GB" uiCulture="en-GB"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM