C# 获取当前日期在指定日期范围内是第几周

        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

上一篇:Ajax在IE浏览器会出现中文乱码解决办法


下一篇:IE内嵌google chrome frame解决浏览器兼容问题