2

我按小时对数据进行分组,如下所示:

group c by new { date = new DateTime(Date.Year, Date.Month, Date.Day, Date.Hour, 5, 0), name = c.Name } into g

我想得到这样的东西:10.05 - 11.05 当我调试代码时,日期会像我预期的那样返回。但数据仍分组在10.00 - 11.00.

我希望我能解释一下。这样做的逻辑是什么?

谢谢。

4

2 回答 2

1
let offSetDate = Date.AddMinutes(-5)  //shift back so that Year,Month,Day,Hour are all that matter.
let groupKey = new {
  date = new DateTime(offSetDate.Year, offSetDate.Month, offSetDate.Day, offSetDate.Hour, 5, 0),
  name = c.Name
}
group c by groupKey into g
于 2012-11-09T15:41:46.193 回答
1
var groups = dList.GroupBy(d => (d.Ticks - 5*TimeSpan.TicksPerMinute) / TimeSpan.TicksPerHour)
                .Select(g => g.ToList())
                .ToList();
于 2012-11-09T15:05:29.990 回答