日期时间在ASP.NET c中不起作用#

日期时间在ASP.NET c中不起作用#,asp.net,Asp.net,在VisualWebDeveloper2010中,我已经在一个网站上工作了几个星期,一直在使用DateTime。突然,昨天它没有工作,抛出了一个越界异常。我已经将我的工作的渐进版本保存到了v.45,以前的工作也没有运行过。以下代码是我所做工作的总结,但即使是单独的代码也不起作用: DateTime yearToday = DateTime.Today; string dtStr = yearToday.ToString("d"); 引发异常: 索引超出了数组的边界 此外: 不会引

在VisualWebDeveloper2010中,我已经在一个网站上工作了几个星期,一直在使用DateTime。突然,昨天它没有工作,抛出了一个越界异常。我已经将我的工作的渐进版本保存到了v.45,以前的工作也没有运行过。以下代码是我所做工作的总结,但即使是单独的代码也不起作用:

DateTime yearToday = DateTime.Today;       
string dtStr = yearToday.ToString("d");
引发异常:

索引超出了数组的边界

此外:

不会引发异常,但不会显示

有人能解释一下吗

@科尔顿:电脑时钟工作正常

@乔·伊诺斯:我只在一台电脑上安装了VWD2010和SQL。我没有改变任何东西

@Michael Liu:这是堆栈跟踪

[IndexOutOfRangeException: Index was outside the bounds of the array.] 
System.String.get_Chars(Int32 index) +0
Ref.genRef() in f:\WORKSTATION_Main\WebProjects\site\2014-12-11_ASP\site_40\don\pDon.aspx.cs:80
don_pDon.sessionString(String inRef) in f:\WORKSTATION_Main\WebProjects\site\2014-12-11_ASP\site_40\don\pDon.aspx.cs:165
don_pDon.Page_Load(Object sender, EventArgs e) in f:\WORKSTATION_Main\WebProjects\site\2014-12-11_ASP\site_40\don\pDon.aspx.cs:57
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 
System.Web.UI.Control.OnLoad(EventArgs e) +92 
System.Web.UI.Control.LoadRecursive() +54 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information:
Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.34237

您的系统时钟设置是否正确?您是否已将Windows中的区域设置更改为令人生厌的设置,或将注册表中的任何区域设置弄乱?如果您将该代码带到另一台机器上,我相信它会正常运行。此代码在我的机器上运行良好,因此问题出在系统的其他位置。从堆栈跟踪来看,错误似乎与日期时间无关。看起来您正在为
Ref.genRef
中的字符串编制索引,而您的索引超出了字符串的长度。您是否已在调试器中逐步查看代码以了解发生了什么?
[IndexOutOfRangeException: Index was outside the bounds of the array.] 
System.String.get_Chars(Int32 index) +0
Ref.genRef() in f:\WORKSTATION_Main\WebProjects\site\2014-12-11_ASP\site_40\don\pDon.aspx.cs:80
don_pDon.sessionString(String inRef) in f:\WORKSTATION_Main\WebProjects\site\2014-12-11_ASP\site_40\don\pDon.aspx.cs:165
don_pDon.Page_Load(Object sender, EventArgs e) in f:\WORKSTATION_Main\WebProjects\site\2014-12-11_ASP\site_40\don\pDon.aspx.cs:57
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 
System.Web.UI.Control.OnLoad(EventArgs e) +92 
System.Web.UI.Control.LoadRecursive() +54 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information:
Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.34237