string格式的日期时间字符串转为DateTime类型

string格式的日期时间字符串转为DateTime类型
//方法二:DateTime.ParseExact()
string dateString = "20110526";
DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd",System.Globalization.CultureInfo.CurrentCulture);
//或者
DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture);

string strTime = "20150711";
                string timeFormat = "yyyyMMdd";
                return DateTime.ParseExact(strTime, timeFormat, System.Globalization.CultureInfo.CurrentCulture);


你可能感兴趣的:(DateTime)