首页  编辑  

计算两个时间中出现了多少个星期几

Tags: /C#/日期时间/   Date Created:

public 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;

} /* TotalWeeks */