W = (D + 2 * m + 3 * (m + 1)/5 + Y/4-y/100 + Y/400) mod 7
In the formula, D indicates the date in the date, M indicates the number of months, and y indicates the number of years.
Note: In this formula, and are regarded as the 13th and 14th months of the previous year. For example, if-1-10 is used, the formula is converted to 2003-13-10 for calculation.
Below is C #'sCodeImplementation
Code
/// <Summary>
/// Calculate the week of the input date
/// </Summary>
/// <Param name = "year"> Year, yyyy format: 2009 </Param>
/// <Param name = "month"> Month: an integer between 1 and 12 </Param>
/// <Param name = "day"> Date: an integer between 1 and 31 </Param>
/// <Returns> The number of weeks. One to seven represents Monday and seven represents Sunday. </Returns>
Int Week ( Int Year, Int Month, Int Day ){
If (Month = 1 | Month = 2 ){
Month + = 12 ;
Year -= 1 ;
}
Int Week = (Day + 2 * Month + 3 * (Month + 1 ) / 5 + Year + Year / 4 - Year / 100 + Year / 400 ) % 7 ;
Return (Week + 1 );
}