每隔一秒輸出當前時間的java代碼

import java.text.SimpleDateFormat;
import java.util.Date;


public class DisplayTime {


public static void main(String[] args) {
Thread thread = new Thread(){
public void run(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
while(true){
System.out.println(sdf.format(new Date()));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
};
thread.start();
}


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章