c# 获取月份中的第一天和最后一天 c#根据年份和月份获得本月最后一天

关键字: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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值