package com.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
public class MainTest {
public static void main(String[] args) {
Timer timer=new Timer();
MyTimerTask task=new MyTimerTask();
timer.schedule(task, new Date(), 1000);
}
}
class MyTimerTask extends java.util.TimerTask {
String now;
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
now=sdf.format(new Date());
System.out.println(now);
}
public String getNow(){
return this.now;
}
}
阅读(312) | 评论(0) | 转发(0) |