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