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
时间: 2024-10-10 10:04:57