根据年月日 获取星期
/// <summary>根据日期,获得星期几</summary> /// <param name="y">年</param> /// <param name="m">月</param> /// <param name="d">日</param> /// <returns>星期几,1代表星期一;7代表星期日</returns> private static int getWeekDay(int y, int m, int d) { if (m == 1) m = 13; if (m == 2) m = 14; int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7 + 1; return week; } /// <summary> /// 获取星期 /// </summary> public static string GetWeek() { int m = System.DateTime.Today.Month; int y = System.DateTime.Today.Year; int d = System.DateTime.Today.Day; int weeks = getWeekDay(y, m, d); string Week = ""; switch (weeks) { case 1: Week = "周一"; break; case 2: Week = "周二"; break; case 3: Week = "周三"; break; case 4: Week = "周四"; break; case 5: Week = "周五"; break; case 6: Week = "周六"; break; case 7: Week = "周日"; break; } return Week; }