日期:2014-05-18 浏览次数:20922 次
IList<Datetime> Submitted = 2012-02-12 10:41:15 2012-02-13 09:56:02 2012-02-13 09:56:45 2012-02-13 12:53:43 2012-02-13 12:53:57 2012-02-13 12:53:58 2012-02-13 00:00:00 2012-02-15 14:23:46 var list=Enumerable.Range(0,DateTime.DaysInMonth(2012,2)).Select(i=>new DateTime(2012,2,1).AddDays(i)).ToList(); IList<DateTime> dList = new List<DateTime>(); dList = list.Except(Submitted).ToList(); //这个地方得出的还是29,没有和Submitted比对成功啊,应该怎么办??
dList = list.Except(Submitted.Select(p=>p.Date)).ToList();
------解决方案--------------------
IList<DateTime> Submitted = new List<DateTime> { Convert.ToDateTime("2012-02-12 10:41:15"), Convert.ToDateTime("2012-02-13 09:56:45"), Convert.ToDateTime("2012-02-13 09:56:02"), Convert.ToDateTime("2012-02-15 14:23:46") }; var list = Enumerable.Range(0, DateTime.DaysInMonth(2012, 2)).Select(i => new DateTime(2012, 2, 1).AddDays(i)).ToList(); IList<DateTime> dList = new List<DateTime>(); list.Except(Submitted,new DateTimeCompare()).ToList().ForEach(x => Console.WriteLine(x.ToString("yyyy-MM-dd"))); public class DateTimeCompare : IEqualityComparer<DateTime> { #region IEqualityComparer<DateTime> 成员 public bool Equals(DateTime x, DateTime y) { if (x.ToString("yyyy-MM-dd").Equals(y.ToString("yyyy-MM-dd"))) return true; else return false; } public int GetHashCode(DateTime obj) { return obj.Year + obj.Month + obj.Day; } #endregion }