字符串20100830如何转换成日期型啊,希望各位高手帮一下忙

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入要计算的日期:");
                string input = Console.ReadLine();            if (input.Length < 8)
                {
                    Console.WriteLine("你输入的日期格式不正确");
                }
                else
                {
                    DateTime dt = new DateTime();
                    dt = DateTime.Parse(input);
                    int year = dt.DayOfYear;
                    int mouth = dt.Month;
                    int day=dt.Day;
                    DateTime dt1 = new DateTime(year, 1, 1);
                    DateTime dt2 = new DateTime(year, mouth, day);
                    //int a = dt2.DayOfYear;
                    int days = (dt2 - dt1).Days + 1;
                    Console.WriteLine("你输入的日期是该年的第{0}天。", days.ToString());
                }
                Console.ReadLine();
            }
        }
    }
      

  2.   

    DateTime.Parse("20100830", "yyyyMMdd");
      

  3.   

    给个方法给你,你自己改下就可以了:
    public string FormatDateExact(object inValue)
    {
           if(inValue==null || inValue.ToString().Length==0)return "";
           return DateTime.ParseExact(inValue.ToString(),"yyyyMMdd",System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy/MM/dd");
    }
      

  4.   


                DateTime dt = DateTime.ParseExact("20100830", "yyyyMMdd",null);            Console.WriteLine(dt);
      

  5.   

            Dim str As String = "20100830"        Dim dt As DateTime = DateTime.Parse(str.Substring(0, 4) & "/" & str.Substring(4, 2) & "/" & str.Substring(6, 2))
      

  6.   

    DateTime dt = DateTime.ParseExact("20100830", "yyyyMMdd",null);