关键字:c# 获取月份最后一天 年份 月份
清风夜影寒:http://qfyyh.iteye.com
正文:
获取一个月份中最早的一天和最后的一天。在C#的DateTime类中,已经提供了现成的函数,下面分别用两个简单的函数表示:
private DateTime [color=red]GetFirstDayOfMonth[/color](int Year,int Month)
{
[color=green]//你见过不是从1号开始的月份么?没有
//那么,直接返回给调用者吧!
//良好的一个编程习惯就是你的代码让人家看了简单易懂[/color]
return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-1");
}
private DateTime [color=red]GetLastDayOfMonth[/color](int Year, int Month)
{
[color=green]//这里的关键就是 DateTime.DaysInMonth 获得一个月中的天数[/color]
int Days = DateTime.DaysInMonth(Year, Month);
return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-" + Days.ToString());
}
清风夜影寒:http://qfyyh.iteye.com
清风夜影寒:http://qfyyh.iteye.com
正文:
获取一个月份中最早的一天和最后的一天。在C#的DateTime类中,已经提供了现成的函数,下面分别用两个简单的函数表示:
private DateTime [color=red]GetFirstDayOfMonth[/color](int Year,int Month)
{
[color=green]//你见过不是从1号开始的月份么?没有
//那么,直接返回给调用者吧!
//良好的一个编程习惯就是你的代码让人家看了简单易懂[/color]
return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-1");
}
private DateTime [color=red]GetLastDayOfMonth[/color](int Year, int Month)
{
[color=green]//这里的关键就是 DateTime.DaysInMonth 获得一个月中的天数[/color]
int Days = DateTime.DaysInMonth(Year, Month);
return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-" + Days.ToString());
}
清风夜影寒:http://qfyyh.iteye.com