public static void main(String[] args) { // TODO Auto-generated method stub
final Timer timer = new Timer(); timer.schedule(new TimerTask() { private int i = 1; private Calendar c = Calendar.getInstance(); public void run() { if(c.get(Calendar.MINUTE)==10) { System.out.println("10分钟到了"); this.cancel(); timer.cancel(); }
windows平台提供SetTimer。
如果不用这个,那就在计算程序中插入计时函数,计算时间再确定是继续计算还是退出。
// TODO Auto-generated method stub
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
private int i = 1;
private Calendar c = Calendar.getInstance();
public void run() {
if(c.get(Calendar.MINUTE)==10)
{
System.out.println("10分钟到了");
this.cancel();
timer.cancel();
}
}
}, new Date(), 1); }