这两种情况有什么不同吗?
Convert.ToDateTime
和
DateTime.Parse
哪个更快,哪个更安全?
这两种情况有什么不同吗?
Convert.ToDateTime
和
DateTime.Parse
哪个更快,哪个更安全?
每answer on another forum from Jon Skeet...
转换ToDateTime使用DateTime.使用当前
如果您不确定字符串是否为有效的DateTime
,请既不使用,也不使用,而使用DateTime.TryParse()
如果您确定字符串是有效的DateTime
,并且您知道格式,那么您还可以考虑DateTime.ParseExact()
或DateTime.TryParseExact()
方法.