Rounds a TimeSpan value to the nearest timespan given
Source
public static TimeSpan RoundToNearest(this TimeSpan a, TimeSpan roundTo){
long ticks = (long)(Math.Round(a.Ticks / (double)roundTo.Ticks) * roundTo.Ticks);
return new TimeSpan(ticks);
}
Example
TimeSpan example = DateTime.Now.TimeOfDay;
Console.WriteLine(example.RoundToNearest(TimeSpan.FromMinutes(15)));