日期:2014-05-17  浏览次数:20861 次

将20121201转化成datetime类型
将string = "20121201";转化成datetime类型
------最佳解决方案--------------------
  DateTime dt = DateTime.ParseExact(Times, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
------其他解决方案--------------------
            DateTime dt = Convert.ToDateTime(Regex.Replace("20121201",@"(\d{4})(\d{2})(\d{2})","$1-$2-$3"));

------其他解决方案--------------------
如果是时间类型,好像不会有楼主要的格式。
但可以为datetime类型增加一个自定义属性。
------其他解决方案--------------------
引用:
引用:DateTime dt = DateTime.ParseExact(Times, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);转化后的时间也要是“20121201”

你可以在使用的时候tostring就可以了:
DateTime dt = DateTime.ParseExact("20121201", "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); 
Console.WriteLine(dt.ToString("yyyyMMdd"));//20121201
------其他解决方案--------------------
引用:
DateTime dt = DateTime.ParseExact(Times, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
转化后的时间也要是“20121201”
------其他解决方案--------------------
引用:
如果是时间类型,好像不会有楼主要的格式。
但可以为datetime类型增加一个自定义属性。
我用来做文件名字
------其他解决方案--------------------
format.tostring("yyyymmdd")
------其他解决方案--------------------
又多学了一招!!
------其他解决方案--------------------
DateTime dt = DateTime.Parse(filename.Substring(0, 4) + "/" + filename.Substring(4, 2) + "/" + filename.Substring(6, 2));
                dt = dt.AddDays(1);
                nextfilename = (dt).ToString("yyyyMMdd") + "_00.dat";