幼儿园优质课
不支持此配件c#经典题⽬--年、周、⽇期计算
癞蛤蟆歇后语///
玩游戏闪退怎么办
/// 获取⼀年中指定的⼀周的开始⽇期和结束⽇期。开始⽇期为星期⼀。 ///
/// Write by vrhero /// 年(1 到 9999) /// 周(1 到 53) /// 确定⾸周的规则 /// 当此⽅法返回时,则包含参数 year 和 weeks 指定的周的开始⽇期的 System.DateTime 值;如果失败,则为 System.DateTime.MinValue。如果参数 year 或 weeks 超出有效范围,则操作失败。该参数未经初始化即被传递。 /// 当此⽅法返回时,则包含参数 year 和 weeks 指定的周的结束⽇期的 System.DateTime 值;如果失败,则为System.DateTime.MinValue。如果参数 year 或 weeks 超出有效范围,则操作失败。该参数未经初始化即被传递。 /// 成功返回 true,否则为 fal。 public static bool GetDaysOfWeeks(int year, int weeks, CalendarWeekRule weekrule, out DateTime first, out DateTime last) { //初始化 out 参数 first = DateTime.MinValue; last = DateTime.MinValue; //不⽤解释了吧... if (year < 1 | year > 9999) return fal; //⼀年最多53周地球⼈都知道... if (weeks < 1 | weeks > 53) return fal; //取当年⾸⽇为基准...为什么?容易得呗... DateTime firstCurr = new
DateTime(year, 1, 1); //取下⼀年⾸⽇⽤于计算... DateTime firstNext = new DateTime(year + 1, 1, 1); //将当年⾸⽇星期⼏转换为数字...星期⽇特别处理...ISO 8601 标准... int dayOfWeekFirst = (int)firstCurr.D
雪中悍刀行语录
ayOfWeek; if (dayOfWeekFirst == 0) dayOfWeekFirst = 7; //得到未经验证的周⾸⽇... first = firstCurr.AddDays((weeks - 1) * 7 - dayOfWeekFirst + 1); //周⾸⽇是上⼀年⽇期的情况... if (first.Year < year) { switch (weekrule) { ca CalendarWeekRule.FirstDay: //不⽤解释了吧... first = firstCurr; break; ca CalendarWeekRule.FirstFullWeek: //顺延⼀周... first = first.AddDays(7); break; ca CalendarWeekRule.FirstFourDayWeek: //周⾸⽇距年⾸⽇不⾜4天则顺延⼀周... if
(firstCurr.Subtract(first).Days > 3) { first = first.AddDays(7); } break; default: break; } } //得到未经验证的周末⽇... last =
first.AddDays(7).AddSeconds(-1); switch (weekrule) { ca CalendarWeekRule.FirstDay: //周末⽇是下⼀年⽇期的情况... if (last.Year > year) last = firstNext.AddSeconds(-1); el if (last.DayOfWeek != DayOfWeek.Monday) last = first.AddDays(7 -
(int)first.DayOfWeek).AddSeconds(-1); break; ca CalendarWeekRule.FirstFourDayWeek: //周末⽇距下⼀年⾸⽇不⾜4天则提前⼀周... if (last.Year > year && firstNext.Subtract(first).Days < 4) { first = first.AddDays(-7); last = last.AddDays(-7); } break; default: break; } return true; } ///
碳酸饮料杀精吗/// 获取指定⽇期在某年的周数 ///最后的时刻
/
辟邪之物// /// private int GetWeekOfYear(DateTime dt) { GregorianCalendar gc = new GregorianCalendar(); return gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday); }