日期:2014-05-18 浏览次数:20451 次
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(); } }