/// <summary> /// 中式的获取上周一的方法 /// </summary> /// <param name="dt"></param> /// <param name="weekday"></param> /// <returns></returns> public DateTime getWeekUpOfDate(DateTime dt, DayOfWeek weekday) { int intWeekday = Convert.ToInt32(weekday.ToString("d")); //因为C#提供的枚举中周日是0,所以这时候应该单独处理改为7,计算公式就是(n+6) if (intWeekday==0) { intWeekday = 7; } dt = dt.AddDays(-(intWeekday+6)); return dt; }
/// <summary> /// 获取上个月一号的时间 /// </summary> /// <param name="datetime"></param> /// <returns></returns> private DateTime FirstDayOfPreviousMonth(DateTime datetime) { return datetime.AddDays(1 - datetime.Day).AddMonths(-1); } /// <summary> /// 获取上个月最后一天的时间 /// </summary> /// <param name="datetime"></param> /// <returns></returns> private DateTime LastDayOfPrdviousMonth(DateTime datetime) { return datetime.AddDays(1 - datetime.Day).AddDays(-1); }