//线程类:
public class CountTime extends Thread{
@Override
public void run() {
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowTime = sdf.format(date);
System.out.println(nowTime);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
```java
//测试类:
public class test {
public static void main(String[] args) {
CountTime t=new CountTime();
t.start();
}
}