import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class timer {
public static void main(String[] args) {
// TODO todo.generated by zoer
Timer timer = new Timer();
timer.schedule(new MyTask(), 0, 1000); //任务等待0秒后开始执行,之后每秒执行一次
}
}
class MyTask extends TimerTask {
@Override
public void run() {
Date day = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(day)+"\n");
}
}
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class timer {
public static void main(String[] args) {
// TODO todo.generated by zoer
Timer timer = new Timer();
timer.schedule(new MyTask(), 0, 1000); //任务等待0秒后开始执行,之后每秒执行一次
}
}
class MyTask extends TimerTask {
@Override
public void run() {
Date day = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(day)+"\n");
}
}