Here you can find the source of getDelay(int hour, int min)
public static long getDelay(int hour, int min)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static long getDelay(int hour, int min) { if (hour == -1) { return 0; }/*from w ww . j ava2 s . c o m*/ Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(new Date()); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, min); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); long delay = calendar.getTime().getTime() - new Date().getTime(); if (delay <= 0) { delay = delay + 24 * 60 * 60 * 1000; } return delay; } }