如何取到两个日期中的每一天,并且打印出来

代码如下

static void Main(string[] args)
        {
            DateTime one = Convert.ToDateTime("2009-02-01");
            DateTime two = Convert.ToDateTime("2008-12-01");

            for (DateTime dt = two; dt < one; dt = dt.AddDays(1))
            {
                string year = dt.Year.ToString();
                string month = dt.Month.ToString();
                string day = dt.Day.ToString();

                if (month.Length == 1)
                {
                    month = "0" + month;
                }

                if (day.Length == 1)
                {
                    day = "0" + day;
                }

                string time_M = year + "-" + month + "-" + day;
                Console.WriteLine(time_M);
            }
            Console.ReadLine();
        }

 

posted @ 2013-06-20 16:48  殇琉璃  阅读(310)  评论(0编辑  收藏  举报