int Month = 9;
//第一天
DateTime TheFirstDay = Convert.ToDateTime(DateTime.Now.Year + "/" + Month + "/1 00:00:00");
//最后一天
DateTime TheLastDay = TheFirstDay.AddMonths(1).AddDays(-TheFirstDay.Day).AddHours(23).AddMinutes(59).AddSeconds(58);
string first = "第一天:" + TheFirstDay;
string end = "最后一天:" + TheLastDay;
Console.WriteLine(first);
Console.WriteLine(end);
方法二:
与方法一同理,经过测试可以用
for (int i = 1; i <= 12; i++)
{
string BaseTimeStr = "2015/" + i + "/3";
DateTime BaseTime = Convert.ToDateTime(BaseTimeStr);
DateTime FirstDay = new DateTime(BaseTime.Year, BaseTime.Month, 1);
DateTime LastDay = FirstDay.AddMonths(1).AddDays(-1);
Console.WriteLine("初始时间:{0}", BaseTime);
Console.WriteLine("月初:{0}", FirstDay);
Console.WriteLine("月末:{0}", LastDay);
Console.WriteLine("*********分割线*********");
}
Console.ReadLine();