标签:
public static int GetWeekOfDay(DateTime start, DateTime end) { //总周数 var weekCount = Math.Ceiling(Convert.ToDouble((end - start).Days / 7)); //用于存储日期 var weekDic = new Dictionary<DateTime, int>(); var today = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); for (var i = 0; i < weekCount; i++) { for (var j = 0; j < 7; j++) { weekDic.Add(start.AddDays(i * 7 + j), i + 1); } } return weekDic.ContainsKey(today) ? weekDic[today] : 1; }
调用: var result = DateHelper.GetWeekOfDay(new DateTime(2016, 04, 04), new DateTime(2016, 04, 25));
输出:3
标签:
原文地址:http://www.cnblogs.com/zhuiyi/p/5421300.html