C# 处理DateTime算法,取某月第1天及最后一天

代码如下所示:

/// <summary>
/// 取得某月的第一天
/// </summary>
/// <param name="datetime">要取得月份第一天的时间</param>
/// <returns></returns>
private DateTime FirstDayOfMonth(DateTime datetime)
{
return datetime.AddDays( - datetime.Day);
} /// <summary>
/// 取得某月的最后一天
/// </summary>
/// <param name="datetime">要取得月份最后一天的时间</param>
/// <returns></returns>
private DateTime LastDayOfMonth(DateTime datetime) return datetime.AddDays( - datetime.Day).AddMonths().AddDays(-);
} /// <summary>
/// 取得上个月第一天
/// </summary>
/// <param name="datetime">要取得上个月第一天的当前时间</param>
/// <returns></returns>
private DateTime FirstDayOfPreviousMonth(DateTime datetime)
{
return datetime.AddDays( - datetime.Day).AddMonths(-);
} /// <summary>
/// 取得上个月的最后一天
/// </summary>
/// <param name="datetime">要取得上个月最后一天的当前时间</param>
/// <returns></returns>
private DateTime LastDayOfPrdviousMonth(DateTime datetime)
{
return datetime.AddDays( - datetime.Day).AddDays(-);
}
上一篇:php学习笔记-获取表单数据


下一篇:Android BroadcastReceiver 面试解析