日期:2014-05-18  浏览次数:21138 次

如果将字符串“20070826”转换为日期类型,谢谢
谢谢

------解决方案--------------------
string s = "20070826 ";
DateTime vDateTime;
if (DateTime.TryParseExact(s, "yyyyMMdd ", null,
System.Globalization.DateTimeStyles.None, out vDateTime))
MessageBox.Show(vDateTime.ToString());
else MessageBox.Show( "输入错误 ");
------解决方案--------------------
try

string test = "20070826 ";
DateTime dt = DateTime.ParseExact(test, "yyyyMMdd ", System.Globalization.CultureInfo.InvariantCulture);

------解决方案--------------------
string test = "20070826 ";
DateTime dt = DateTime.ParseExact(test, "yyyyMMdd ", System.Globalization.CultureInfo.InvariantCulture);
Response.Write( " <script> alert( ' " + string.Format( "{0:yyyy-MM-dd} ", dt) + " '); </script> ");
------解决方案--------------------
DateTime d = new DateTime();
DateTime.TryParse( "2001-01-01 ", out d);

Response.Write(d.ToString());
------解决方案--------------------
楼上正解!