AlgorithmAs follows:
Kemlerson Formula
W = (D + 2 * m + 3 * (m + 1)/5 + Y/4-y/100 + Y/400) mod 7
In the formula, D indicates the number of days in the date, M indicates the number of months, and y indicates the number of years.
Note: There is a difference between the formula and other formulas:
The year and month are regarded as the 13 and 14 months of the previous year. For example, if the year-1-10 is used, the formula is converted to 2003-13-10.
CodeAs follows:
// Y-year, M-month, D-Date
String Caculateweekday ( Int Y, Int M, Int D)
{
If (M = 1 ) M = 13 ;
If (M = 2 ) M = 14 ;
Int Week = (D + 2 * M + 3 * (M + 1 ) / 5 + Y + Y / 4 - Y / 100 + Y / 400 ) % 7 ;
String Weekstr = "" ;
Switch (Week)
{
Case 7 : Weekstr = " Monday " ; Break ;
Case 1 : Weekstr = " Tuesday " ; Break ;
Case 2 : Weekstr = " Wednesday " ; Break ;
Case 3 : Weekstr = " Thursday " ; Break ;
Case 4 : Weekstr = " Friday " ; Break ;
Case 5 : Weekstr = " Saturday " ; Break ;
Case 6 : Weekstr = " Sunday " ; Break ;
}
Return Weekstr;
}
Call method:
Label2.text = caculateweekday (maid, 9 );