【C#日期系列(二)】--C#获取一段时间有多少个星期几

#region 统计一段时间内有多少个星期几
        ///<summary> 
        ///统计一段时间内有多少个星期几 
        ///</summary> 
        ///<param name="AStart">开始日期</param> 
        ///<param name="AEnd">结束日期</param> 
        ///<param name="AWeek">星期几</param> 
        ///<returns>返回个数</returns> 
        public static int TotalWeeks(DateTime AStart, DateTime AEnd, DayOfWeek AWeek)
        {
            TimeSpan vTimeSpan = new TimeSpan(AEnd.Ticks - AStart.Ticks);
            int Result = (int)vTimeSpan.TotalDays / 7;
            for (int i = 0; i <= vTimeSpan.TotalDays % 7; i++)
                if (AStart.AddDays(i).DayOfWeek == AWeek)
                    return Result + 1;
            return Result;
        }
        #endregion

 

posted @ 2017-07-12 14:18  代码小六  阅读(1620)  评论(0编辑  收藏  举报