DateTime ParseExact字符串不能识别为DateTime C# [英] DateTime ParseExact string was not recognize as a DateTime C#
本文介绍了DateTime ParseExact字符串不能识别为DateTime C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解析字符串作为日期时间,但我得到一个错误。这里我的代码
$ $ p $ return DateTime.ParseExact(01/01/0001 12:00:00 AM,dd / MM / yyyy HH:mm:ss tt,CultureInfo.InvariantCulture);
日期和格式是从DataBase获得的字符串,我试图将其添加到DataColumn DateTime数据类型。
有什么问题?
$ b $ p
谢谢。
<您正试图解析 DateTime
确切地,因此格式必须以
解析确切地说,
DateTime.ParseExact(01/01/0001 12:00:00 AM,dd / MM / yyyy hh:mm:ss tt,CultureInfo.InvariantCulture);
I'm trying to parse string as DateTime but I'm getting an error. here my code
return DateTime.ParseExact("01/01/0001 12:00:00 AM", "dd/MM/yyyy HH:mm:ss tt", CultureInfo.InvariantCulture);
The date and its format is got from DataBase as string and I'm trying to add it to a DataColumn DateTime data type.
What's the problem?
Thanks.
解决方案
You are trying to parse the DateTime
exactly, therefore the format has to be exact
DateTime.ParseExact("01/01/0001 12:00:00 AM", "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
这篇关于DateTime ParseExact字符串不能识别为DateTime C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文