错误到来:-String未被识别为有效的DateTime。 [英] Error come:-String was not recognized as a valid DateTime.
本文介绍了错误到来:-String未被识别为有效的DateTime。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码
DateTime SubmitDate = Convert.ToDateTime(txtPayrollStart.Text);
in运行时此代码出错。日期时间格式是dd-MM-yyyy .plz告诉我什么是正确的格式
解决方案
发生此错误是因为txtPayrollStart中的值。文本
不是DateTime
。
要检查日期时间,请始终使用DateTime。 TryParse
[ ^ ]以确保您要转换的值是有效的日期时间。
您好,
试试这种方式
DateTime DT;
DateTime.TryParseExact(dateTime,
yyyy / MM / dd,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out dt);
my code
DateTime SubmitDate = Convert.ToDateTime(txtPayrollStart.Text );
in this code come to error when it is run. date time format is dd-MM-yyyy .plz tell me what is the right format
解决方案
This error occurs because the value intxtPayrollStart.Text
is not aDateTime
.
To check for date times, always useDateTime.TryParse
[^] to ensure the value you are converting is a valid date time.
Hello ,
Try this way
DateTime dt; DateTime.TryParseExact(dateTime, "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
这篇关于错误到来:-String未被识别为有效的DateTime。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文