现在的位置: 首页 > 综合 > 正文

c#取时间范围技巧

2012年05月22日 ⁄ 综合 ⁄ 共 530字 ⁄ 字号 评论关闭
//取当前整个星期时间范围
DateTime startDate = DateTime.Today.Date.AddDays(-(int)DateTime.Today.DayOfWeek), // prev sunday 00:00
endDate = startDate.AddDays(7); // next sunday 00:00
//取当前整个月时间范围
int CurrentYear = DateTime.Today.Year;
int CurrentMonth = DateTime.Today.Month;
DateTime startDate = new DateTime(CurrentYear, CurrentMonth, 1);
DateTime endDate = startDate.AddMonths(1).AddMinutes(-1);

//使用

var v = from x in doc.Descendants("Transaction")
        where ((DateTime)x.Element("Current_Date")).Date >= startDate
        && ((DateTime)x.Element("Current_Date")).Date < endDate
        select new Transaction(x);

抱歉!评论已关闭.