错误解决方案[FormatException:String未被识别为有效的DateTime。] [英] Solution of error [FormatException: String was not recognized as a valid DateTime.]

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

问题描述

我的代码是:



my code is:

objclientregis.RegDate = Convert.ToDateTime(regdate);



但是当我调试时会引发以下错误:

[FormatException:String未被识别为有效的DateTime。]



我也将其转换为字符串,如下所示,但同样的错误被抛出..


but when I debug then following error is raised:
[FormatException: String was not recognized as a valid DateTime.]

I also convert it in string as following but same error is thrown..

objclientregis.RegDate = Convert.ToDateTime(Convert.ToString( regdate));



请帮助我..

提前谢谢..


plz help me..
Thanks in advance..

推荐答案

因为你的regdate字符串不代表有效的日期格式。



使用
Its because your regdate String doesn't represent a valid Date format .

Use
DateTime.TryParse()


Quote:

[FormatException:String未被识别为有效的DateTime。]

[FormatException: String was not recognized as a valid DateTime.]

这意味着字符串 regdate 无法转换为 DateTime ,因为格式错误。



查看以下内容获得清晰图片的答案。

1. 字符串未被识别为有效的日期时间。 [ ^ ]

2. 格式异常字符串未被识别为有效日期时间 [ ^ ]

This means the string regdate can't be converted to DateTime as the format is wrong.

Check the following answers for a clear picture.
1. String was not recognized as a valid DateTime.[^]
2. Format exception String was not recognized as a valid DateTime[^]


试试这样

Try like this
DateTime dt = Convert.ToDateTime(regdate);
objclientregis.RegDate=dt;


这篇关于错误解决方案[FormatException:String未被识别为有效的DateTime。]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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