2014-03-28 68 views

回答

1

如果你有「項目」的一個DateTime屬性的集合,你要計算這個星期全部的,這應該工作:

var calendar = DateTimeFormatInfo.CurrentInfo.Calendar; 
var weekRule = DateTimeFormatInfo.CurrentInfo.CalendarWeekRule; 
var firstDay = DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek; 
int week = calendar.GetWeekOfYear(DateTime.Today, weekRule, firstDay); 
int thisWeekBookings = items 
    .Count(i => i.DateTimeScheduled.Year == DateTime.Today.Year && 
     week == calendar.GetWeekOfYear(i.DateTimeScheduled, weekRule, firstDay)); 
+0

完美工作,謝謝! – user2915962