package package_1; import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask; public class Test_1 { public static void main(String[] args) {
Timer timer = new Timer();
timer.schedule(new Task(), 2000, 1000);//(执行的操作,等待多少毫秒执行,每隔多少毫秒执行一次)
} } class Task extends TimerTask{
public void run(){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormat.format(new Date()));
}
}