我有一個名單的日期來顯示它在網格中,我想添加一個小時RANGE2:名單的日期,addHours列出LINQ
private void grid_loaded(object sender, RoutedEventArgs e)
{
var data = new List<EntityViewModel>
{
new EntityViewModel { aDay = new DateTime(1980, 1, 1, 12, 0, 12) },
new EntityViewModel { aDay = new DateTime(1983, 1, 1, 12, 23, 12) },
new EntityViewModel { aDay = new DateTime(1985, 6, 14, 12, 0, 12) },
new EntityViewModel { aDay = new DateTime(1990, 7, 3, 12, 23, 12) },
new EntityViewModel { aDay = new DateTime(1995, 8, 1, 4, 23, 12) },
new EntityViewModel { aDay = new DateTime(1996, 1, 1, 12, 0, 12) },
new EntityViewModel { aDay = new DateTime(2000, 1, 1, 12, 0, 12) },
new EntityViewModel { aDay = DateTime.Now }
};
var range = data.Where(i => i.aDay.Year >= 1983 && i.aDay.Year <= 1996).ToList();
var range2 = range.Where(i => i.aDay.Date.IsDaylightSavingTime() == true).ToList();
}
我嘗試這樣:
var range3 = range.Where(i => i.aDay.Date.IsDaylightSavingTime() == true).ToList();
range3.ForEach(i => i.aDay.AddHours(1));
這樣的:
foreach (var item in range2.Where(x => x.aDay != null))
{
item.aDay.AddHours(1);
}
這:
var range5 = range2.Where(i => i.aDay != null).Select(i => { i.aDay.AddHours(1); return i; }).ToList();
但它不會做任何事情,總是相同小時。
鑑於你的代碼,我想說的是增加一個小時夏令是錯誤的路要走,看看'ToUniversalTime()'代替,看看它是否你想要做什麼。如果沒有,請查看'DateTimeOffset',通常'DateTime'不是用來處理偏移量的。 IsDaylightSavingTime()的作用:指示此DateTime實例是否在當前時區的夏令時範圍內。 IE瀏覽器,即使你添加一小時,它仍然會聲明是夏令時。 – flindeberg