Reproduced:
http://blog.csdn.net/livening/article/details/6049341/
Code:
/// <summary> ///get the first day of a month/// </summary> /// <param name= "datetime" >to get the time of the first day of the month</param> /// <returns></returns> Privatedatetime firstdayofmonth (datetime datetime) {returnDatetime. AddDays (1-datetime. Day); } /**//// <summary> ///get the last day of a month/// </summary> /// <param name= "datetime" >to get the time of the last day of the month</param> /// <returns></returns> Privatedatetime lastdayofmonth (datetime datetime)returnDatetime. AddDays (1-DateTime. Day). AddMonths (1). AddDays (-1); } /**//// <summary> ///get the first day of last month/// </summary> /// <param name= "datetime" >to get the current time of the first day of the month</param> /// <returns></returns> Privatedatetime firstdayofpreviousmonth (datetime datetime) {returnDatetime. AddDays (1-DateTime. Day). AddMonths (-1); } /**//// <summary> ///get the last day of last month/// </summary> /// <param name= "datetime" >to get the current time of the last day of last month</param> /// <returns></returns> Privatedatetime lastdayofprdviousmonth (datetime datetime) {returnDatetime. AddDays (1-DateTime. Day). AddDays (-1); }
WinForm------datetime Gets the first day and the last day of the month