需要将时间字符串转换为时间类型。时间字符串格式如下:
"yyyyMMddHHmmss"
怎么转呢,可以这样:
[TestMethod]
public void TestDateTime()
{
DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
dtFormat.FullDateTimePattern = "yyyyMMddHHmmss";
DateTime dt = DateTime.ParseExact("20180101000000", dtFormat.FullDateTimePattern,dtFormat);
Assert.AreEqual(2018, dt.Year);
}