0:15,0:30,0:45,1:00,1:15,1:30,1:45,2:00,2:15,2:30,2:45,.....etc.
根据我的要求,我需要在Timer-Task Scheduler中实现。
private class TimerExample{
private static Timer timer = new Timer();
private static Calendar getFirstTime() {
Calendar cal = Calendar.getInstance();
int currentMinute = cal.get(Calendar.MINUTE);
if (currentMinute < 45) {
cal.set(Calendar.MINUTE, 45);
}
if (currentMinute < 30) {
cal.set(Calendar.MINUTE, 30);
}
if (currentMinute < 15) {
cal.set(Calendar.MINUTE, 15);
}
if (currentMinute >= 45) {
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + 1);
cal.set(Calendar.MINUTE, 0);
}
cal.set(Calendar.SECOND, 0);
return cal;
}
public static void main(String... args) {
Calendar firstTaskTime = getFirstTime();
System.out.println("Task will start at: " + firstTaskTime.getTime());
timer.schedule(new MyTask(), firstTaskTime.getTime(), 1000 * 60 * 15);
}
}