读书人

关于string.format怎么格式日期

发布时间: 2011-12-10 22:22:01 作者: rapoo

关于string.format如何格式日期
我想把 "20070621153214 "格式化为 "2007-06-21 15:32:14 ",请问string.format能做到吗,要怎么做呢?

[解决办法]
private static string FormatAsDate(string input)
{
StringBuilder sb = new StringBuilder(input);
int index = sb.Length - 2;
sb.Insert(index, ": ");
index -=2;
sb.Insert(index, ": ");
index-=2;
sb.Insert(index, " ");
index -= 2;
sb.Insert(index, "- ");
index -= 2;
sb.Insert(index, "- ");
return sb.ToString();
}

读书人网 >C#

热点推荐