下班倒计时-Java

实在无聊,又不想学习,就写了这个玩意。欢迎大佬指导优化

public class testController extends Thread{
@Override
public void run() {
try {
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Date date = sdf.parse(“2020-07-21 18:00:00”);
long millis = date.getTime();
for (int i=0 ; i< Integer.MAX_VALUE; i++){
Date endDate = new Date();
long endMillis = endDate.getTime();
if(millis > endMillis){
Thread.sleep(1000);
System.out.println(“距离下班还有:” + ((millis-endMillis)/1000)/60+“分:”+ ((millis-endMillis)/1000)%60 +“秒”);
}else {
System.out.println(“下班了!!!”);
break;
}
}
}catch (Exception e){
e.printStackTrace();
}
}

public static void main(String[] args) {
    Thread thread = new testController();
    thread.run();
}

你可能感兴趣的:(java)