t_info.solutionTime = Convert.ToDateTime(context.Request.QueryString["solutionDate"] == null ? "" : context.Request.QueryString["solutionDate"]);
我正在尝试转换日期格式,但它总是返回此异常
System.FormatException: String was not recognized as a valid DateTime
此格式的日期:2015-08-25 18:45:55
最佳答案
可能是因为 ""
不是有效的日期/时间值。您可以使用 DateTime.MinValue
或其他一些“神奇”值来表示 null
:
t_info.solutionTime =
context.Request.QueryString["solutionDate"] == null
? DateTime.MinValue
: Convert.ToDateTime(context.Request.QueryString["solutionDate"]);
关于c# - C# 中的日期时间分析器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32214375/