import java.util.*;
public class MyTest extends Thread {
Timer timer;
int defaultHour;//开始时钟(小时)
int defaultMin;//开始分钟(分钟)
int defaultInterval;
//时间间隔(分钟)
Date date;//开始时间
Calendar curCalendar;
Calendar calendar;//
public MyTest() {
defaultHour = 0;
defaultMin = 0;
defaultInterval = 24*60;
curCalendar = Calendar.getInstance();
calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, defaultHour);
calendar.set(Calendar.MINUTE, defaultMin);
while (calendar.before(curCalendar)) {
calendar.add(Calendar.MINUTE, defaultInterval);
System.out.println(calendar.getTime().toString());
}
date = calendar.getTime();
timer = new Timer();
}
public void run() {
System.out.println("=========");
System.out.println(curCalendar.getTime().toString() + " schedule started.");
System.out.println(date.toString() + " first schedule start.");
System.out.println("=========");
timer.schedule(new InterfaceTask(), date, defaultInterval * 60 * 1000);
}
public static void main(String[] args) {
try{
new MyTest().start();
}catch (Exception e) {
e.printStackTrace();
}
}
class InterfaceTask extends TimerTask {
public void run() {
System.out.println("=========");
System.out.println(Calendar.getInstance().getTime().toString() + " scheduledo
ing start!");
try {
//TODO:
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(Calendar.getInstance().getTime().toString() + " scheduledo
ing end!");
System.out.println("=========");
}
}
}