DateTime转换为string类型:
string类型转换为DateTime:
string dateString = "20161010";
DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd",
System.Globalization.CultureInfo.CurrentCulture);
这里的"yyyyMMdd"对应"20161010",也可换做
string dateString = "2016/10/10";
DateTime dt = DateTime.ParseExact(dateString, "yyyy/MM/dd",
System.Globalization.CultureInfo.CurrentCulture);
效果如图:
对于2016-10-10这种格式,可直接使用:
string dateString = “2016-10-10”;
DateTime dt =DateTime.Parse(dateString);