title: Calculate number of milliseconds until next occurence of a time
body: <p>I feel like this is something really simple, but my Google Fu is letting me down as I keep finding difference calculations.</p>
  
  <p>I have a time (e.g. 1800 hours) stored in a <code>DateTime</code> object. The date is null and immaterial. All I want to know is how many milliseconds until the NEXT occurrence of that time.</p>
  
  <p>So, if I run the calculation at 0600 - it will return 12 hours (in ms). At 1750, it will return ten minutes (in ms) and at 1900 it will return 24 hours (in ms).</p>
  
  <p>All the things I can find show me how to calculate differences, which doesn't work once you're past the time.</p>
  
  <p>Here is what I tried, but fails once you're past the time and gives negative values:</p>
  
  <pre><code>DateTime nowTime = DateTime.Now;
  TimeSpan difference = _shutdownTime.TimeOfDay - nowTime.TimeOfDay;
  double result = difference.TotalMilliseconds;
  </code></pre>