C# 根据日期计算星期几

 1 region 根据年月日计算星期几(Label2.Text=CaculateWeekDay(2004,12,9);)
 2 /// <summary>
 3 /// 根据年月日计算星期几(Label2.Text=CaculateWeekDay(2004,12,9);)
 4 /// </summary>
 5 /// <param name="y"></param>
 6 /// <param name="m"></param>
 7 /// <param name="d"></param>
 8 /// <returns></returns>
 9 public static string CaculateWeekDay(int y,int m, int d)
10 {
11 if(m==1) m=13;
12 if(m==2) m=14;
13 int week=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7+1;
14 string weekstr="";
15 switch(week)
16 {
17 case 1: weekstr="星期一"; break;
18 case 2: weekstr="星期二"; break;
19 case 3: weekstr="星期三"; break;
20 case 4: weekstr="星期四"; break;
21 case 5: weekstr="星期五"; break;
22 case 6: weekstr="星期六"; break;
23 case 7: weekstr="星期日"; break;
24 }
25 return weekstr;
26 }
27 #endregion

 

C# 根据日期计算星期几

上一篇:VB.net 与 C# 的对应逻辑运算符


下一篇:Win8下安装MAC OS