每隔一段固定的时间执行一段代码
Timer
public class Timer01 {
//定时器
public static void main(String[] args) throws ParseException {
Timer t = new Timer();
//指定时间
t.schedule(new Blog(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").parse("2019-6-14 11:30:30 000"),1000);
}
}
//指定任务
class Blog extends TimerTask {
public void run() {
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(new Date()));
}
}