代入参数年y,月m,日d 即可返回所得的星期
public static string getWeekDay(int y, int m, int d)
{
if(m==1) {m=13;y--;}
if(m==2) {m=14;y--;}
int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y/400) % 7 + 1;
string strweek="";
switch (week)
{
case 1:
strweek = "星期一";
break;
case 2:
strweek = "星期二";
break;
case 3:
strweek = "星期三";
break;
case 4:
strweek = "星期四";
break;
case 5:
strweek = "星期五";
break;
case 6:
strweek = "星期六";
break;
case 7:
strweek = "星期日";
break;
}
return strweek;
}
{
if(m==1) {m=13;y--;}
if(m==2) {m=14;y--;}
int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y/400) % 7 + 1;
string strweek="";
switch (week)
{
case 1:
strweek = "星期一";
break;
case 2:
strweek = "星期二";
break;
case 3:
strweek = "星期三";
break;
case 4:
strweek = "星期四";
break;
case 5:
strweek = "星期五";
break;
case 6:
strweek = "星期六";
break;
case 7:
strweek = "星期日";
break;
}
return strweek;
}