/// <summary>
/// 计算指定年月日是星期几
/// </summary>
/// <param name="y">年</param>
/// <param name="m">月</param>
/// <param name="d">日</param>
/// <returns>是周六返回6,周天返回7,其余返回0</returns>
public static int Whether_Weekend(int y, int m, int d)
{
if (m == 1 || m == 2)
{
m += 12;
y--;
}
int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; // 基姆拉尔森公式
if (week == 5)
{
return 6;
}
else if (week == 6)
{
return 7;
}
else
{
return 0;
}
}
判断指定的年月日是不是周六或周天
最新推荐文章于 2022-08-08 18:17:16 发布