C#内置的日期类是在是太强大了,很多东西根本不需要我们自己去编写,这里计算当前日期是星期几,C#不用基姆拉尔森算法很简单就可以获得。
//获取当前日期是星期几 string dt = DateTime.Today.DayOfWeek.ToString(); protected string GetWeek(string dt) { string week; //根据取得的英文单词返回汉字 switch (dt) { case "Monday": week ="星期一"; break ; case "Tuesday": week = "星期二"; break; case "Wednesday": week = "星期三"; break; case "Thursday": week = "星期四"; break; case "Friday": week = "星期五"; break; case "Saturday": week = "星期六"; break; case "Sunday": week = "星期日"; break; } }