错误:字符串未被识别为有效的DateTime. [英] Error: String was not recognized as a valid DateTime.

查看:90
本文介绍了错误:字符串未被识别为有效的DateTime.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用ajax日历扩展程序和文本框.将文本框值转换为日期时间格式时出现错误:"String was not recognized as a valid DateTime."
我正在使用以下代码:

I''m using an ajax calendar extender and a text box in my project. While converting the textbox value to the datetime format error is coming : "String was not recognized as a valid DateTime."
I''m using the following code:

<tr><td>
        <asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtfrom" runat="server" />
        </td><td><asp:TextBox ID="txtfrom" runat="server" CssClass="txtbx"></td></tr>

DateTime dt1 = Convert.ToDateTime(txtfrom.Text);



如何获取日期格式的texbox值?

谢谢.



How can I get the texbox value in date format?

Thank you.

推荐答案

查看这些链接,您可能会有所了解
http://msdn.microsoft.com/en-us/library/xhz1w05e.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/system.datetime. compare.aspx [^ ]
see these links you may get some idea
http://msdn.microsoft.com/en-us/library/xhz1w05e.aspx[^]
http://msdn.microsoft.com/en-us/library/system.datetime.compare.aspx[^]


我已将格式"属性更改为

< asp:calendarextender id ="CalendarExtender1" targetcontrolid ="txtfrom" runat ="server" format ="dd/MM/yyyy" xmlns:asp =#unknown">

现在工作正常.

谢谢.
I''ve changed the property ''Format'' as

<asp:calendarextender id="CalendarExtender1" targetcontrolid="txtfrom" runat="server" format="dd/MM/yyyy" xmlns:asp="#unknown">

and now it is working fine.

Thank you.


使用

Use

DateTime dt1 = DateTime.ParseExact(txtFrm.Text, "dd-MM-YYYY", null);






然后就可以了:-)
最好的:-)






Then it Works Fine :-)
All the Best :-)


这篇关于错误:字符串未被识别为有效的DateTime.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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