DateTime.Parse和Convert.ToDateTime有什么区别?

DateTime.Parse和Convert.ToDateTime有什么区别?

问题描述:

Convert.ToDateTime

DateTime.Parse

哪一个是速度更快或更安全的使用?

Which one is faster or which is more secure to use?

每一个answer从乔恩斯基特另一个论坛 ...

Convert.ToDateTime使用DateTime.Parse内部,与目前
  文化 - 除非你把它传递null,在这种情况下,它会返回
  DateTime.MinValue。

Convert.ToDateTime uses DateTime.Parse internally, with the current culture - unless you pass it null, in which case it returns DateTime.MinValue.

如果你不知道字符串是有效的日期时间,既不使用,转而使用DateTime.TryParse()

If you're not sure string is a valid DateTime, use neither and instead, use DateTime.TryParse()

如果你确定该字符串是一个有效的DateTime,你知道的格式,你也可以考虑DateTime.ParseExact()或DateTime.TryParseExact()方法。

If you're sure the string is a valid DateTime, and you know the format, you could also consider the DateTime.ParseExact() or DateTime.TryParseExact() methods.