response.setContentType(
"text/html;charset=UTF-8");
response.setHeader(
"Cache-Control",
"no-cache");
PrintWriter out = response.getWriter();
try {
if (
"submit".equals(request.getParameter(
"action"))) {
//交卷
//TODO:這裏作交卷處理
out.println(
"已交卷");
}
else {
//倒計時
//設置結束時間
Calendar timeend = Calendar.getInstance();
timeend.set(2008, 10, 7, 14, 50, 0);
long end = timeend.getTimeInMillis();
//out.print(sdf.format(timeend.getTime())+"<br>");
//獲取當前時間
Calendar rightNow = Calendar.getInstance();
//out.print(sdf.format(rightNow.getTime())+"<br>");
long now = rightNow.getTimeInMillis();
//計算剩餘時間
int left = (
int) (end - now);
if (left <= 0) {
//時間到
out.print(
"over");
}
else {
int leftHour = left / (1000 * 60 * 60);
left = left % (1000 * 60 * 60);
int leftMinute = left / (1000 * 60);
left = left % (1000 * 60);
int leftSecond = left / (1000);
out.print(leftHour +
"時" + leftMinute +
"分" + leftSecond +
"秒");
}
}
}
finally {
out.close();
}