判断闰,平年,获取每月的天数 包括2月
[C#] 纯文本查看 复制代码 /// <summary>
/// 判断闰,平年,获取每月的天数 包括2月
/// </summary>
/// <param name="year"></param>
/// <param name="month"></param>
/// <returns></returns>
public static string GetMonthLastDay(int year, int month)
{
string day = DateTime.Now.Day.ToString();
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = "31";
}
else if (month == 2)
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
day = "29";
}
else
{
day = "28";
}
}
else
{
day = "30";
}
return day;
}
|