日期:2014-05-17 浏览次数:20787 次
magaView.HasMonth = db.Library.Where(a => a.CategoryID == categoryId).GroupBy(a => a.TimeBook.Year * 12 + a.TimeBook.Month - 1).Select(a => a.Key).ToList(). //找寻有杂志的月份
Select(a => new DateTime((int)Math.Floor(a / 12.0), a % 12 + 1, 1)).OrderByDescending(a => a.Year).ToList();
List<DateTime> li = new List<DateTime>() { DateTime.Now, DateTime.Now.AddMonths(1), DateTime.Now.AddMonths(1), DateTime.Now.AddMonths(2), DateTime.Now.AddMonths(2), DateTime.Now.AddYears(1), DateTime.Now.AddYears(1).AddMonths(2), DateTime.Now.AddYears(2).AddMonths(1), DateTime.Now.AddYears(2) };
li.ForEach(x => Console.WriteLine(x));
Console.WriteLine("--------------------------------");
var query = li.OrderByDescending(a => a.Year).ThenBy(a => a.Month).ToList();
query.ForEach(x => Console.WriteLine(x));
List<DateTime> list = new List<DateTime>
{
DateTime.Now.AddYears(1),
DateTime.Now.AddYears(1).AddMonths(1),
DateTime.Now.AddYears(1).AddMonths(2),
DateTime.Now.AddYears(1).AddMonths(3),
DateTime.Now.AddYears(1).AddMonths(4),
DateTime.Now.AddYears(1).AddMonths(5),
DateTime.Now.AddYears(1).AddMonths(6),
DateTime.Now.AddYears(2),
DateTime.Now.AddYears(2).AddMonths(1),
DateTime.Now.AddYears(2).AddMonths(1)