https://www.cnblogs.com/ithuo/p/5481755.html
方式一:Convert.ToDateTime(string)
Convert.ToDateTime(string)
注意:string格式有要求,必须是yyyy-MM-dd hh:mm:ss
方式二:Convert.ToDateTime(string, IFormatProvider)
1 DateTimeFormatInfo dtFormat = new System.GlobalizationDateTimeFormatInfo(); 2 dtFormat.ShortDatePattern = "yyyy/MM/dd"; 3 DateTime dt = Convert.ToDateTime("2016/10/10", dtFormat);
说明:任意格式可自定义规则。
方式三:DateTime.ParseExact()
string dateString = "20161010"; DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
说明:任意格式可自定义规则。