import java.text.SimpleDateFormat;
import java.util.Date;
public class ThreaTest implements Runnable {
@Override
public void run() {//线程执行方法
while(true){
try {
Date date = new Date();
String date2 =
new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(date);
System.out.println(date2);//打印当前时间
Thread.sleep(1000);//休眠1ms
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Thread t = new Thread(new ThreaTest());
t.start();
}
}