日期:2014-05-18 浏览次数:20926 次
public int TotalWorkday(DateTime AStart, DateTime AEnd) { TimeSpan vTimeSpan = new TimeSpan(AEnd.Ticks - AStart.Ticks); // 跨度多少个星期,每个星期五个工作日 int Result = ((int)vTimeSpan.TotalDays / 7) * 5; // 计算余下的日期中的工作日 for (int i = 0; i <= vTimeSpan.TotalDays % 7; i++) switch (AStart.AddDays(i).DayOfWeek) { case DayOfWeek.Saturday: case DayOfWeek.Sunday: break; default: Result++; break; } return Result; } /* TotalWorkday */ private void button1_Click(object sender, EventArgs e) { Text = TotalWorkday(new DateTime(2007, 9, 1), new DateTime(2007, 10, 1)).ToString(); }
------解决方案--------------------
int weeks = new System.Globalization.GregorianCalendar().GetWeekOfYear(System.DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
int weeks1 = new System.Globalization.GregorianCalendar().GetWeekOfYear(System.DateTime.Now.AddDays(100), System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
int week=weeks1-week;