This example uses the Kimlarsson formula to calculate the day of the week based on the date:
First look at Baidu Encyclopedia of Kimlarsson formula definition:
Kimlarsson 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 different formula in the formula:
Consider January and February as the January or March and January or April of the previous year, for example: if it is 2004-1-10, convert it to: 2003-13-10 to substitute the formula.
1, the client (using Ajax method calls):
$.get (' Caculateweekday ', {y:2016, M:8, D:9}, function (Result) {
alert (result);
})
2, service side:
<summary>
///Calculate a specific date is the day of the week
///</summary>
///<param name= "Y" > Year </param>
///<param name= "M" > Month </param>
///<param name= "D" > Day </param>
///<returns ></returns> public
string caculateweekday (int y, int m, int d)
{
if (m = = 1 | | m = = 2)
{
m + +;
y--;
}
Int week = (d + 2 * m + 3 * (M + 1)/5 + y + Y/4-y/100 + y/400)% 7;
String weekstr = "";
Switch (week)
{case
0:weekstr = "Monday";
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 = "Week Seven"; break;
return weekstr;
}
The above is a small set up to introduce C # based on the date of the day to calculate the example code of the week, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!