简体   繁体   English

asp.net中的Convert.ToDateTime问题

[英]Problem with Convert.ToDateTime in asp.net

I have an application that works without any problem in a spanish server. 我有一个可以在西班牙服务器上正常运行的应用程序。

When i uploaded the application into the online server (an english windows), im getting exceptions (of type "input string is not a valid Datetime/Int32") with Convert.ToDateTime and Convert.ToInt32. 当我将应用程序上载到在线服务器(英语窗口)时,使用Convert.ToDateTime和Convert.ToInt32获得了异常(“输入字符串不是有效的Datetime / Int32”类型)。 Are any web.config line that could help me in this matter? 是否有任何web.config行可以帮助我解决此问题? I tried adding a globalization element with the Spanish culture, but didnt worked. 我试图在西班牙文化中加入全球化元素,但没有奏效。

Could you give me a hand? 你能帮我一下吗?

Thanks in advance. 提前致谢。 Josema. 荷西

You need: 你需要:

System.Globalization.CultureInfo culture = 
              new System.Globalization.CultureInfo("es-ES");
DateTime myDateTime = Convert.ToDateTime(string, culture);

您是否在将String.Format()调用中的CultureInfo参数指定为IFormatProvider

You might have set uiculture instead of culture in the globalization element, see: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx . 您可能在全球化元素中设置了uiculture而不是文化,请参见: http : //msdn.microsoft.com/zh-cn/library/bz9tc508.aspx

...
    <globalization culture="es-MX" />
...

You can also try using a more specific culture (like the one above es - mexico). 您也可以尝试使用更具体的文化(例如es上的文化-墨西哥)。

Ps. 附言 I have a site working like that (actually with culture="en" as in my case I needed to force english as my development computer was configured with spanish at the time). 我有一个像这样的网站(实际上是使用culture =“ en”,因为在我的开发计算机当时配置了西班牙语的情况下,我需要强制使用英语)。

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

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