我有一个SQL查询,它将日期从ASP.NET中的日历程序输入到数据库中,但是现在我已经将它部署到了Azure中,我得到了这个错误:"String未被识别为有效的DateTime“这是我在C#中使用的代码
string fromFormat = "dd/MM/yyyy";
string toFormat = "yyyy-MM-dd";
string date = diarycalender.SelectedDate.ToShortDateString();
DateTime newDate = DateTime.ParseExact(date, fromFormat, null);
string date2 = (newDate.ToString(toFormat));
DateTime date3 = DateTime.Parse(date2);
cmd.Parameters.AddWithValue("@date", date3);谁能解释一下为什么我现在得到这个错误,而它在本地运行良好,但不再工作了?
发布于 2014-10-20 05:04:28
默认情况下,Azure网站是使用美国语言环境创建的,根据这篇博客文章:
http://blogs.msdn.com/b/ericgolpe/archive/2010/12/29/windows-azure-date-time-and-locale.aspx
看起来你想使用英国地区作为你的约会时间,这就是为什么事情在本地运行正常,但当你将网站上传到Azure时却不是这样。
根据这个博客http://yossidahan.wordpress.com/2012/02/17/locale-on-windows-azure/,有几种方法可以解决这个问题,其中最简单的方法应该是在web.config的system.web中包含以下内容:
<globalization culture="en-GB" uiCulture="en-GB" />https://stackoverflow.com/questions/23371695
复制相似问题