我按小时对数据进行分组,如下所示:
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
当我调试代码时,Date 按我的预期返回。但数据仍分组在 10.00 - 11.00
之间。
我希望我能解释一下。这样做的逻辑是什么?
谢谢。
最佳答案
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
关于c# - linq 按小时范围分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13310390/