Conversion from string “31/03/2012” to type 'Date' is not valid

拜拜、爱过 提交于 2019-12-20 03:06:29

问题


My web app is running perfectly in asp vb.net editor. But when i run my web app through IIS7 then i get this error. What am i missing in configuring IIS7? Is there anyone who can suggest something?

Thanks in Advance


回答1:


Because your IIS7 is configured for the English Language and that date is probably Italian or something similar. You'll have to tell to the Date.Parse which culture to use.

Something like

dateValue = Date.Parse(yourDate, CultureInfo.CreateSpecificCulture("it-IT"))

Or you can change the culture in your IIS7

Here there are the instructions

for example if you use the UI

Using the UI Open IIS Manager and navigate to the level you want to manage. (omissis)

In Features View, double-click .NET Globalization.

On the .NET Globalization page, in the property sheet, click to select the global setting you want to edit, and select a value from the drop-down list.

In the Actions pane, click Apply.

Or you could set the culture of your app in the web.config

<system.web>
    <globalization culture="it-IT" uiCulture="it-IT"/>
</system.web>



回答2:


If you are sure that the date is always in exactly that format, then you can use ParseExact instead:

var date = DateTime.ParseExact(
               "31/03/2012",
               "dd/MM/yyyy",
               System.Globalization.CultureInfo.InvariantCulture);



回答3:


You can also use the CDate function to parse the date.

Dim dDate As Date = CDate("31/03/2012")

The advantage of using this function over the DateTime parsing functions is that you can feed it any acceptable format of date string and it will convert it. It will throw an error if it can't parse the date.



来源:https://stackoverflow.com/questions/7945310/conversion-from-string-31-03-2012-to-type-date-is-not-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!