title: Is there a better way in C# to round a DateTime to the nearest 5 seconds?
body: <p>I want to round a DateTime to the nearest 5 seconds.  This is the way I'm currently doing it but I was wondering if there was a better or more concise way?</p>
  
  <pre><code>DateTime now = DateTime.Now;
  int second = 0;
  
  // round to nearest 5 second mark
  if (now.Second % 5 &gt; 2.5)
  {
      // round up
      second = now.Second + (5 - (now.Second % 5));
  }
  else
  {
      // round down
      second = now.Second - (now.Second % 5);
  }
  
  DateTime rounded = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, second);
  </code></pre>
  
  <p>Please note that I've found <a href="https://stackoverflow.com/questions/152774/is-there-a-better-way-to-trim-a-datetime-to-a-specific-precision">these</a> <a href="https://stackoverflow.com/questions/166145/whats-the-best-way-to-round-a-net-date-object-to-the-nearest-minute-closed">two</a> previous questions, however they <i>truncate</i> rather than <i>round</i> the time.</p>