Convert string to DateTime

string d1="2005-10-1 12:12:12";
    DateTime dt1=DateTime.Parse(d1);
    string d2="20051001121212";
    DateTime dt2=DateTime.ParseExact(d2,"yyyyMMddHHmmss",System.Globalization.DateTimeFormatInfo.CurrentInfo);
    Console.WriteLine(d1 + "\t" + dt1.ToString());
    Console.WriteLine(d2 + "\t" + dt2.ToString());

DateTime dt2=DateTime.ParseExact()
可以定义任何形式的时间格式;
原文地址:https://www.cnblogs.com/neozhu/p/238637.html