import java.util.Timer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;
class MyTask extends TimerTask
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void run(){
System.out.println(sdf.format(new Date()));
}
}
public class t1{
public static void main(String[] args)
{
MyTask myTask = new MyTask();
Timer timer = new Timer();
timer.schedule(myTask, 2000, 1000);// 2秒后开始启动任务,以后每秒执行一次.
System.out.println("main end");
}
}