例如:某时间时20100730160550,怎么把他用代码截成年。月。日。时。分。秒的形式 如:2010 07 30 16 05 50
string time=".........";

解决方案 »

  1.   

    DateTime dt=DateTime.ParseExact("20100730160550","YYYYMMDDHHmmss",null);
    dt.ToString("YYYY MM dd HH mm ss");
      

  2.   

      DateTime dt = DateTime.ParseExact("20100730160550", "yyyyMMddHHmmss", null);
                string s=dt.ToString("yyyy MM dd HH MM ss");
      

  3.   

    用datatime试试,不行了就只能用substring了
      

  4.   

    DateTime dt = DateTime.ParseExact("20100730160550", "yyyyMMddHHmmss", null);
                DateTime dt = DateTime.ParseExact("20100730160550", "yyyyMMddHHmmss", null);            Console.WriteLine(dt.Year);
                Console.WriteLine(dt.Month);
                Console.WriteLine(dt.Day);
                Console.WriteLine(dt.Hour);
                Console.WriteLine(dt.Minute);
                Console.WriteLine(dt.Second);
      

  5.   

    Convert.ToDateTime(日期).ToString("yyyy MM dd")
    应该是你想要的吧~
      

  6.   

    年月日时分秒的数字的位数都是固定的,4,2,2,2,2,2
    string str="20100730160550";
    string stryear=str.SubString(0,4);//年
    string strMouth=str.SubString(4,2);//月
    string strDay=str.SubString(6,2);//日
    string strHour=str.SubString(7,2);//时
    string strSecond=str.SubString(10,2);//分
    string strMin=str.SubString(12,2);//秒
      

  7.   

    DadeTime.Parse(string time).ToString("yyyy-MM-dd-HH-MM-ss")
      

  8.   

    如果20100730160550是字符串的话
    DateTime t=Convert.ToDateTime(“20100730160550”);
    string s=t.year.tostring()+t.month.tostring("D2")+t.day.tostring("D2")+t.hour.tostring()+t.minute.tostring()+t.second.tostring();
      

  9.   

    DateTime dt=DateTime.ParseExact("20100730160550","YYYYMMDDHHmmss",null);
    dt.ToString("YYYY MM dd HH mm ss");
      

  10.   

    可以用Regex.
    string dateTime = "20100730160550";
                Regex rg = new Regex(@"^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$");
                Match match = rg.Match(dateTime);
                if (!match.Success)
                {
                    Console.WriteLine("wrong datetime format");
                }
                else
                {
                    string year = match.Groups[1].Value;
                    string month = match.Groups[2].Value;
                    string day = match.Groups[3].Value;
                    string hour = match.Groups[4].Value;
                    string minute = match.Groups[5].Value;
                    string second = match.Groups[6].Value;
                    Console.WriteLine("Year={0}, Month={1}, Day={2}, Hour={3}, Minute={4}, Second={5}", year, month, day, hour, minute, second);
                }