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

日期字符串转成固定格式,求较快速的方法!
日期都是8位,格式为yyyyMMdd ,转为 yyyy-MM-dd
如:20081028  ==》 2008-10-28

不分解字符串,有没有较快速的方法。求指教!

------解决方案--------------------
用正则表达式
s = "20081028";
Match m = Regex.Match(s, @"(\d{4})(\d{2})(\d{2})");
s1 = string.Format("{0}-{1}-{2}", m.Groups[1].Value, m.Groups[2].Value, m.Groups[3].Value);
------解决方案--------------------
 string str = "20081028";
            str = Regex.Replace(str, @"(\d{4})(0\d
------解决方案--------------------
1[012])([012]\d
------解决方案--------------------
3[01])", "$1-$2-$3");
          
------解决方案--------------------
一共才8位,怎么处理速度上都不会有明显的差异
string result = Regex.Replace("20081028", "(?<=^(?:.{4}
------解决方案--------------------
.{6}))", "-");