sleep打印当前时间

public static void main(String[] args) throws InterruptedException {
        //sleep打印系统时间
        while(true){
            //打印当前时间
            Date date = new Date(System.currentTimeMillis());//获取系统当前时间
            Thread.sleep(1000);
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
            date = new Date(System.currentTimeMillis());
        }
    }


 

//模拟倒计时
public static void tenDown2() throws InterruptedException {
int num=10;
while (true){
Thread.sleep(1000);
System.out.println(num--);
if (num<0){
break;
}
}
}
 
原文地址:https://www.cnblogs.com/rzkwz/p/12484977.html