从字符串“31/03/2012”的转换输入“日期”无效

发布于 2024-12-12 20:48:43 字数 110 浏览 3 评论 0原文

我的网络应用程序在 asp vb.net 编辑器中完美运行。但是当我通过 IIS7 运行我的 Web 应用程序时,我收到此错误。我在配置 IIS7 时缺少什么?有人可以提出建议吗?

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

被你宠の有点坏 2024-12-19 20:48:44

如果您确定日期始终采用该格式,则可以使用 ParseExact 代替:

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

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);
把回忆走一遍 2024-12-19 20:48:44

您还可以使用 CDate 函数来解析日期。

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

与 DateTime 解析函数相比,使用此函数的优点是您可以向其提供任何可接受的日期字符串格式,它会对其进行转换。如果无法解析日期,它将抛出错误。

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.

情话已封尘 2024-12-19 20:48:43

因为您的 IIS7 配置为英语,而该日期可能是意大利语或类似的语言。您必须告诉 Date.Parse 要使用哪种区域性。

或者

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

您可以更改 IIS7 中的文化

这里有 说明

例如,如果您使用 UI

使用 UI 打开 IIS 管理器并导航到您想要的级别
管理。 (省略)

在功能视图中,双击 .NET Globalization。

在 .NET 全球化页面的属性表中,单击以选择
您要编辑的全局设置,然后从
下拉列表。

在“操作”窗格中,单击“应用”。

或者您可以在 web.config 中设置应用程序的文化

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文