("dddd",new ("zh-cn"));
Today I saw some introductions on the implementation of C# on the calculation of the day of the week based on the year, month, day and day:
The algorithm is as follows:
Kim Larson Calculation Formula
W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7
In the formula, d represents the number of days in the date, m represents the number of months, and y represents the number of years.
Note: There is a difference in the formula from other formulas:
Consider January and February as the thirteenth and fourteenth months of the previous year. For example: if it is 2004-1-10, it will be converted into: 2003-13-10 and substituted into the formula to calculate.
The code is as follows:
//y-year, m-month, d-date string CaculateWeekDay(int y,int m,int d) { string[] weekstr ={ "day", "one", "two", "three", "Four", "five", "six" }; if (m < 3) { m += 12; if (y % 400 == 0 || y % 100 != 0 && y % 4 == 0) { d--; } } else { d += 1; } return "Week" + weekstr[(d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7]; }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.