Here you can find the source of getDelay(long delay, long interval)
public static long getDelay(long delay, long interval)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static long getDelay(long delay, long interval) { long current = System.currentTimeMillis(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); try {/*from w w w .j a va 2 s . c o m*/ current = System.currentTimeMillis() - sf.parse(sf.format(new Date())).getTime(); } catch (ParseException e) { } if (current >= delay) { return current - delay; } else { long pastTime = delay - current; return interval - pastTime % interval; } } }