如题  ..  例:我要把 091217 100226  转成  09-12-17 10:02:26  
   困扰好久 ...希望大家帮我下

解决方案 »

  1.   

    Convert.ToDateTime("091217 100223").ToString("yyyy-MM-dd HH:mm:ss")
      

  2.   

    DateTime dat = DateTime.Parse(s);s是个时间字符串
      

  3.   

    static DateTime StrToDateTime(string str)
            {
                Regex  re=new Regex(@"\d{2}");
               MatchCollection  mc = re.Matches(str);
               List<int> list = new List<int>();
               foreach (Match m in mc)
                   list.Add(Convert.ToInt32(m.Value));
               return new DateTime(list[0], list[1], list[2], list[3], list[4], list[5]);
            } DateTime dt = StrToDateTime("091217 100226 ");
                Console.WriteLine(dt.ToString("yy-MM-dd hh-mm-ss"));
      

  4.   

     DateTime dat = new DateTime();
            string h = "09-12-17 10:02:26";
            dat = DateTime.Parse(h);
      

  5.   

                string strDate = "091217 100223";
                strDate = strDate.Replace(" ","");
                strDate = strDate.Trim().Substring(0, 2) + "-" + strDate.Trim().Substring(2, 2) + "-" + strDate.Trim().Substring(4, 2)
                + " " + strDate.Trim().Substring(6, 2) + ":" + strDate.Trim().Substring(8, 2) + ":" + strDate.Trim().Substring(10, 2);
      

  6.   

    DateTime dat = DateTime.Parse(s);s是个时间字符串
    全部是错的
      

  7.   

    Visual Studio里debugger一下,多试几次就有了