日期:2014-05-20  浏览次数:20879 次

字符串转换
怎么将:2007年1月12日   转换成:2007-1-12     谢谢。

------解决方案--------------------
string strSource= "2007年1月12日 ";
string strTarget;
strTarget=strSource.Replace( "年 ", "- ");
strTarget=strTarget.Replace( "月 ", "- ");
strTarget=strTarget.Replace( "日 ", "- ");
MessageBox.Show(strTarget);
------解决方案--------------------
strTarget=strTarget.Replace( "日 ", "- ");
=>
strTarget=strTarget.Replace( "日 ", " ");
------解决方案--------------------
Convert.ToDateTime( "2007年1月12日 ").ToString();
------解决方案--------------------
改一下bitpolar(独自看天)
Convert.ToDateTime( "2007年1月12日 ").ToShortDateString()
------解决方案--------------------
Convert.ToDateTime( "2007年1月12日 ").ToString( "yyyy-MM-dd ");
------解决方案--------------------
str = DateTime.Parse( "2007年1月12日 ").ToString( "yyyy-M-d ");
------解决方案--------------------
String.Format( "{0:d} ", "2007年1月12日 ");