static int countDownTime=100;//用来设置总时间 Timer timer=new Timer(); TimerTask task=new TimerTask() { @Override public void run() { if(countDownTime!=0){ countDownTime--; } } }; timer.schedule(task,0,1000);//放在主函数 long currentTime = System.currentTimeMillis(); //计时180秒 int settime = 180; if ((currentTime - startTime) / 1000 > settime) { System.out.println("Time's up!"); wrongCount=30-correctCount; break ; } else System.out.println(settime - (currentTime - startTime) / 1000 + "s left");
标签:Java,currentTime,System,倒计时,settime,countDownTime,1000 From: https://www.cnblogs.com/muzhaodi/p/17777595.html