c# 获取当前周第一天、最后一天,当前月第一天、最后一天的实现代码

获取当前周工作日第一天、最后一天
int dayOfWeek = Convert.ToInt32(DateTime.Now.DayOfWeek);
int daydiff = (-1) * dayOfWeek + 1;
int dayadd = 5 - dayOfWeek;

DateTime weekStartDate = DateTime.Now.AddDays(daydiff);
DateTime weekEndDate = DateTime.Now.AddDays(dayadd);

获取当前月第一天、最后一天
DateTime now = DateTime.Now;
DateTime monthFirstDate = new DateTime(now.Year, now.Month, 1);
DateTime monthLastDate = firstDate.AddMonths(1).AddDays(-1);

你可能感兴趣的:(java,C++,c,工作,C#)