Problem with Convert.ToDateTime in asp.net

2020-07-27 23:39发布

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. Are any web.config line that could help me in this matter? I tried adding a globalization element with the Spanish culture, but didnt worked.

Could you give me a hand?

Thanks in advance. Josema.

3条回答
霸刀☆藐视天下
2楼-- · 2020-07-28 00:10

Are you specifying a CultureInfo argument, as an IFormatProvider in your String.Format() calls?

查看更多
男人必须洒脱
3楼-- · 2020-07-28 00:23

You might have set uiculture instead of culture in the globalization element, see: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx.

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

You can also try using a more specific culture (like the one above es - mexico).

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).

查看更多
啃猪蹄的小仙女
4楼-- · 2020-07-28 00:33

You need:

System.Globalization.CultureInfo culture = 
              new System.Globalization.CultureInfo("es-ES");
DateTime myDateTime = Convert.ToDateTime(string, culture);
查看更多
登录 后发表回答