DateTime.Parse和Convert.ToDateTime有什么区别? [英] Any difference between DateTime.Parse and Convert.ToDateTime?

查看:1382
本文介绍了DateTime.Parse和Convert.ToDateTime有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Convert.ToDateTime

DateTime.Parse

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

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

推荐答案

每一个<一个href=\"http://bytes.com/topic/c-sharp/answers/482419-convert-todatetime-vs-system-datetime-parse\">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.

这篇关于DateTime.Parse和Convert.ToDateTime有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆