C#获取上个月第一天和最后一天日期的方法

2021-04-24 00:27

阅读:288

int year = DateTime.Now.Year;//当前年

int mouth = DateTime.Now.Month;//当前月

int beforeYear = 0;

int beforeMouth = 0;

if (mouth

{

beforeYear = year – 1;

beforeMouth =12;//上个月

}

else

{

beforeYear = year;

beforeMouth = mouth – 1;//上个月

}

string beforeMouthOneDay = beforeYear + “年” + beforeMouth + “月” + 1 + “日”;//上个月第一天

string beforeMouthLastDay = beforeYear + “年” + beforeMouth + “月” + DateTime.DaysInMonth(year, beforeMouth) + “日”;//上个月最后一天


评论


亲,登录后才可以留言!