DateTime RoundUp(DateTime dt, TimeSpan d){ return new DateTime((dt.Ticks + d.Ticks - 1) / d.Ticks * d.Ticks, dt.Kind);}
例:
var dt1 = RoundUp(DateTime.Parse("2011-08-11 16:59"), TimeSpan.FromMinutes(15));// dt1 == {11/08/2011 17:00:00}var dt2 = RoundUp(DateTime.Parse("2011-08-11 17:00"), TimeSpan.FromMinutes(15));// dt2 == {11/08/2011 17:00:00}var dt3 = RoundUp(DateTime.Parse("2011-08-11 17:01"), TimeSpan.FromMinutes(15));// dt3 == {11/08/2011 17:15:00}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)