milliseconds until next 5th second
<p>So I want to do some monitoring and I want it to be on every fifth minute, so for example if the application starts at 1:47 monitor everything until 1:50 and then reset. I currently have this working for hour but I need to cut it down to every fifth minute and I'm having a little trouble coming up with the math.</p>

<p>I get all of the current time information</p>

<pre><code>  Calendar currentCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  long currentTimeInMillis = currentCalendar.getTimeInMillis();
  int hr = currentCalendar.get(Calendar.HOUR_OF_DAY);
  int min = currentCalendar.get(Calendar.MINUTE);
  int sec = currentCalendar.get(Calendar.SECOND);
  int millis = currentCalendar.get(Calendar.MILLISECOND);
</code></pre>

<p>Now I need to find the next fifth minute, for hour I have this which works.</p>

<pre><code>  millisUntilNextHour = currentTimeInMillis + ((60L - min) * SECONDS_IN_MINUTE * 1000L) + ((60 - sec) * 1000L) + (1000L - millis);
</code></pre>

<p>Can anybody think of a way similar to above to get the milliseconds to the closest fifth minute?</p>
