网站部署时的日期时间格式错误 [英] Datetime format error when site deployed

查看:134
本文介绍了网站部署时的日期时间格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我刚刚在asp.net中使用c#和ms sql server 2008在CRM上建立了一个网站.从已部署的站点更新投诉时,我遇到了DateTime问题.

实际情况:

我已将网站部署在服务器上,并且正在使用服务器IP从远程计算机测试我的网站,当我尝试通过选择任何日期来更新日期时间错误的日期来更新任何投诉时
即像这样:

System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.Convert.ToDateTime(String value) at EditComplaint.UpdateComplaint() in d:\HelpDesk\EditComplaint.aspx.cs:line 135



我曾经使用过ajax日历控件,它的格式设置为"dd-MM-yyyy" ...

奇怪的是,当我通过从Visual Studio运行网站来更新投诉时,它成功完成了,但是在部署网站时却没有完成....此外,系统和服务器的日期时间格式是相同的.

请帮帮我...

谢谢&问候,
您是否在SQL Server上检查过DateTime格式? :laugh:

认真地讲,SQL默认情况下使用"yyyy-MM-dd"(或ISO格式),除非确实需要,否则您不应该手动输入字符串日期-尤其是在Web应用程序中,当用户输入日期可能是以他的本地格式,可能是任何东西.相反,请尽早转换为DateTime(以便您可以引用用户格式),然后将DateTime值作为参数传递给SQL.然后,您可以逆转此过程,并尽可能晚地将DateTime转换为本地化的字符串,并尽可能长时间地使用DateTime值.

Calendar控件的SelectedDate属性已经是DateTime,因此不需要转换!


请检查以下链接:http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [
The odd thing is when i update the complaint by running the website from visual studio it is done successfully but it is not done when website is deployed.... Moreover the datetime format of the system and the server are same.

Please help me out...

Thanks & regards,
Krunal panchal

解决方案

ut did you check the DateTime format on the SQL server? :laugh:

Seriously, SQL uses "yyyy-MM-dd" (or ISO format) by default, and you really shouldn''t hand string dates through unless you really have to - particularly in a web application when the user entered date is likely to be in his local format, which could be anything. Instead, convert to a DateTime as early as possible (so you can reference the user format) and pass the DateTime value to SQL as a parameter. You then reverse the process and convert the DateTime to a localised string as late as possible, working with DateTime values for as long a time as you can.

The SelectedDate property of the Calendar control is a DateTime already, and thus requires no conversion!


Have a check on this links:http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]


这篇关于网站部署时的日期时间格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆