第2个回答 推荐于2021-01-03
package com.MyThread;import java.text.SimpleDateFormat;
import java.util.Date;public class TimeThread extends Thread { public void run() { while (true) {
try {
sleep(5000); } catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Date date = new Date();
SimpleDateFormat dfm = new SimpleDateFormat("hh:mm:ss");
System.out.println(dfm.format(date));
}
} public static void main(String[] args) {
TimeThread tr = new TimeThread();
tr.start(); }}本回答被网友采纳