#region 年、月、星期、日,判断脚本
static bool IsLeapYear(int year)//判断某年是不是闰年
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
//Console.WriteLine("是 闰年");
return true;
}
else
{
//Console.WriteLine("不是 闰年");
return false;
}
}
static int WhatDay(int currentYear, int month)//判断从某年某月第一天是星期几
{
int num;
int totalDays = 0;
for (int i = 1900; i < currentYear; i++)
{
if (IsLeapYear(i))
{
totalDays += 366;
}
else
{
totalDays += 365;
}
}
for (int j = 1; j < month; j++)
{
totalDays += EveryMonthDays(currentYear, j);
}
num = totalDays % 7;
return num + 1;
}
static int EveryMonthDays(int year, int month)//判断某年每个月的天数
{
int i = month;
int monthDay;
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
{
monthDay = 31;
}
else if (i == 4 || i == 6 || i == 9 || i == 11)
{
monthDay = 30;
}
else if (i == 2 && IsLeapYear(year) == true)
{
monthDay = 29;
}
else
{
monthDay = 28;
}
return monthDay;
}
#endregion