import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo03 {
public static void main(String[] args) {
Date date = new Date(System.currentTimeMillis());
while (true){
try {
Thread.sleep(1000);
System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
date=new Date(System.currentTimeMillis());//更新当前时间
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
每隔一秒打印当前时间
最新推荐文章于 2023-09-22 09:55:41 发布