字符串未被识别为有效日期时间显示错误 [英] String was not recognisedas a valid date time show the error

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

问题描述

代码如下:



Code as follows:

DGVCalendar.Rows[row].Cells[0].Value = Convert.ToDateTime(dt1.ToString("dd-MM-yy"));







在上面的行错误显示如下,



字符串未被识别为有效日期时间





我在上面的代码中犯了什么错误。



请帮帮我。



谢谢&问候,

Narasiman P




In the above line error shows as follows,

String was not recognised as a valid date time


What is the mistake i made in the above code.

Please help me.

Thanks & Regards,
Narasiman P

推荐答案





第一名:The有效的DateTime字符串是



yyyy-MM-dd。



第二:你为什么要更改DateTime对象到字符串并返回DateTime?



不应该是这样的:



Hi,

First: The valid DateTime string is

yyyy-MM-dd.

Second: Why are you change the DateTime object to string and back to DateTime?

Shouldn''t be like this:

DGVCalendar.Rows[row].Cells[0].Value = dt1.ToShortDateString();





问候

Jegan



Regards
Jegan


hi professional



基本上字符串未被识别为有效日期时间错误发生当你没有把正确的日期时间格式。



所以试试这个...



hi professional

basically "String was not recognized as a valid date time" error occurs when you did not putting right date time format.

so try this...

DGVCalendar.Rows[row].Cells[0].Value = Convert.ToDateTime(dt1.ToString("dd/MM/yyyy"));



如果不能然后工作正常

表示更多日期时间格式,请参阅以下链接...



http ://www.dotnetperls.com/datetime-format [ ^ ]



乐于助人


and if it will not work properly then
for more date time formats see below link...

http://www.dotnetperls.com/datetime-format[^]

Happy to help


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

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