C# 短日期转换为DateTime

将字符串“201804”转换为DateTime

DateTime dTime = DateTime.ParseExact("201804", "yyyyMM", CultureInfo.CurrentCulture);
View Code

 常见的日期转换

1、Convert.ToDateTime(string date)

  date格式为 yyyy-mm-dd hh:mm:ss

2、Convert.ToDateTime(string date, IFormatProvider formatter)

  formatter 指日期格式

3、DateTime.Parse(dateInput)

参考 http://www.bubuko.com/infodetail-3293058.html

        https://docs.microsoft.com/en-us/dotnet/standard/base-types/parsing-datetime?redirectedfrom=MSDN

猜你喜欢

转载自www.cnblogs.com/ZJ199012/p/12156947.html