我知道有很多相关的问题,但这是别的。字符串未被识别为日期时间的有效分析字符串
ExceptionMessage “:” 字符串未被识别为有效的DateTime “” ExceptionType。 “:” System.FormatException “ ”堆栈跟踪“:” 在System.DateTimeParse.ParseExact(一个String,字符串格式,的DateTimeFormatInfo dtfi,DateTimeStyles风格)在System.DateTime.ParseExact(一个String,字符串格式,提供的IFormatProvider)
我的代码
string bornstring = request.BornDate;
var borndate = DateTime.ParseExact(bornstring, "dd.MM.yyyy", CultureInfo.InvariantCulture);
这不起作用:
string bornstring = request.BornDate;
但这个工程:
string bornstring = "10.10.1959";
,但我100%肯定request.BornDate是String类型的完全一样。我把调试点和检查100次。没有空格或其他字符。完全一样
有你发布的代码和调试器屏幕快照之间的差异。在发布的代码中,您使用'CultureInfo.InvariantCulture',但图像显示为null。 –
有多个Unicode字符,看起来像点。或者字符串中可能还有其他不可打印的字符。你有没有检查有问题的确切代码点? – Ani
将“request.BornDate.ToCharArray()”放入调试器的监视表达式中。您现在还会使用ParseExact()失败的不可打印字符。 –