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

求教算法问题,请高人解答
我想得出一段时间内的所有周六周日的日期,有没有高手会的

------解决方案--------------------
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GetDate
{
    class Program
    {
        static void Main(string[] args)
        {
            List<DateTime> time = new List<DateTime>();
            DateTime startTime = Convert.ToDateTime("2007-1-1");
            DateTime endTime = Convert.ToDateTime("2007-2-1");
            while (startTime.DayOfWeek != DayOfWeek.Saturday)
            {
                startTime=startTime.AddDays(1);
            }
            DateTime firstWeekDay = startTime;
            time.Add(firstWeekDay);
            time.Add(firstWeekDay.AddDays(1));
            while (startTime < endTime)
            {
                startTime = startTime.AddDays(7);
                TimeSpan timeSpan = endTime - startTime;
               
                if (startTime<endTime)
                {
                    time.Add(startTime);
                    time.Add(startTime.AddDays(1));
                }
                else
                {
                    
                }
            }
            foreach (DateTime d in time)
            {
                Console.Write(d+"\n");
            }
            Console.Read();
           
        }

       

    }