获取一个月的第一天及最后一天

来源:互联网 发布:restart windows 编辑:程序博客网 时间:2024/05/21 10:29

            string strYear = cboYear.Text.Trim();
            string strMonth = cboMonth.Text.Trim();
            DateTime dt = Convert.ToDateTime(strYear + "-" + strMonth);
            DateTime d1 = new DateTime(dt.Year, dt.Month, 1);     //d1是选中月的第一天,d2选中月的最后一天,
            DateTime d2 = d1.AddMonths(1).AddDays(-1);            //最后一天的算法是:得到选中月的第一天然后增加一月,再减去一天,

           dtEnd.Value = DateTime.Now.Date.AddSeconds(86399);  //当天23:59:59

原创粉丝点击