using System; public class TestMonth { public static int DayNumOfMonth(DateTime v_date)//获取月份天数 { int v_month,v_year; v_month = v_date.Month; v_year = v_date.Year; switch(v_month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: if (DateTime.IsLeapYear(v_year)) //判断润年 { return 29; } else return 28; default: return 0; } } public static void Main() { Console.WriteLine(TestMonth.DayNumOfMonth(DateTime.Now)); Console.ReadLine(); } };
DateTime.DaysInMonth(year,month)
public class TestMonth
{
public static int DayNumOfMonth(DateTime v_date)//获取月份天数
{
int v_month,v_year;
v_month = v_date.Month;
v_year = v_date.Year;
switch(v_month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: return 31;
case 4:
case 6:
case 9:
case 11: return 30;
case 2:
if (DateTime.IsLeapYear(v_year)) //判断润年
{
return 29;
}
else return 28;
default: return 0;
}
}
public static void Main()
{
Console.WriteLine(TestMonth.DayNumOfMonth(DateTime.Now));
Console.ReadLine();
}
};
DateTime.DaysInMonth(year,month)
就是这个了!!!