import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
public class kaoshidaojishi {
/**
* @param args
*/
public static void main(String[] args) {
boolean isOk = false;
while(true){
if(isOk)
break;
Date date = new Date();
Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = format.format(date);
System.out.println(dateString);
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
if("2015-09-23 13:17:00".equals(dateString)){
int second = 20; //考试时间(秒)
while(true){
long sec = second % 60; //秒
long min = second / 60 % 60; //分
long hour = second / 3600; //时
System.out.println(hour + ":" + min + ":" +sec);
try {
Thread.sleep(1000);
second--;
if(second < 0){
isOk = true;
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
System.out.println("考试结束!");
}
}
可以通过预先设定时间,然后到达指定时间后开始倒计时,考试时间减为0时,倒计时结束,程序停止运行。 |