mTimer.schedule(task,delay,period);
//延迟3秒执行一次,然后每个2秒执行一次
mTimer.schedule(,3000,2000);
//延迟0秒执行一次,然后每个2秒执行一次(即不延迟马上执行一次而不是2秒后执行一次)
mTimer.schedule(,0,2000);
task
TimerTask: task to be scheduled.
delay
long: delay in milliseconds before task is to be executed.
period
long: time in milliseconds between successive task executions.
public class Dingshiqi {
public static void main(String[] args) {
System.out.println(formatTime(System.currentTimeMillis()+""));
Timer mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
// 调用识别结果进度查询接口
System.out.println(formatTime(System.currentTimeMillis()+""));
}
}, 3000, 2000);//延迟3秒执行一次,然后每个2秒执行一次
}
private static Date formatTime(String d) {
Date date=new Date();
// TODO Auto-generated method stub
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// System.out.println("��ǰ����Ϊ��"+simpleDateFormat.format(date));
try {
date=simpleDateFormat.parse(d);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return date;
}
}