日期:2014-05-18 浏览次数:20482 次
static void Main(string[] args) { DateTime beginDate = new DateTime(2012, 1, 1); DateTime endDate = new DateTime(2012, 2, 1); int showWeekOfDay = 6; //这是要查询的出所有的周六 beginDate = beginDate.AddDays(Math.Abs(showWeekOfDay - (Convert.ToInt32(beginDate.DayOfWeek)))); Console.WriteLine(beginDate); do { beginDate = beginDate.AddDays(7); Console.WriteLine(beginDate); } while ((beginDate < endDate)); Console.ReadLine(); }
------解决方案--------------------
DateTime dtStartTime = DateTime.Parse(txtStartTime2.Text);//开始时间 DateTime dtEndTime = DateTime.Parse(txtEndTime2.Text);//结束时间 TimeSpan tsCount = dtEndTime.Subtract(dtStartTime);//两时间之差 int intCount = int.Parse(tsCount.TotalDays.ToString()) + 1; for (int i = 0; i < intCount; i++) { string weeks = dtStartTime.DayOfWeek.ToString(); //比较星期if(weeks=='...........')....... dtStartTime = dtStartTime.AddDays(1);//当前时间+一天 }//end for
------解决方案--------------------
static void Main(string[] args) { DateTime beginDate = new DateTime(2012, 1, 1); DateTime endDate = new DateTime(2012, 2, 1); int showWeekOfDay = 6; //这是要查询的出所有的周六 beginDate = beginDate.AddDays(Math.Abs(showWeekOfDay - Convert.ToInt32(beginDate.DayOfWeek))); Console.WriteLine(beginDate); do { beginDate = beginDate.AddDays(7); if (beginDate > endDate) break; Console.WriteLine(beginDate); } while (beginDate < endDate); Console.ReadLine(); }
------解决方案--------------------
Console.Write("请输入第一个时间:"); DateTime TimeStart = Convert.ToDateTime(Console.ReadLine()); Console.Write("请输入第二个时间:"); DateTime TimeLast = Convert.ToDateTime(Console.ReadLine()); int Subtraction =System.Math.Abs(int.Parse(TimeStart.Subtract(TimeLast).TotalDays.ToString())); for (int i = 0; i <= Subtraction; i++) { if (TimeStart.AddDays(i).DayOfWeek.ToString().ToLower() == "saturday") { Console.WriteLine("日期:"+TimeStart.AddDays(i).ToString()+"是星期六"); } } Console.ReadKey();