1、<SCRIPT language=JavaScript>
var auctionDate = 120;
var startTime = (new Date()).getTime();
var Temp;
var timerID = null;
var timerRunning = false;
function showtime()
{
now = new Date();
var ts=parseInt((startTime-now.getTime())/1000)+auctionDate;
var dateLeft = 0;
var hourLeft = 0;
var minuteLeft = 0;
var secondLeft = 0;
if(ts < 0)
{
ts = 0;
CurHour = 0;
CurMinute = 0;
CurSecond = 0;
} else {
dateLeft =parseInt(ts/86400);
ts = ts - dateLeft * 86400;
hourLeft = parseInt(ts/3600);
ts = ts - hourLeft * 3600;
minuteLeft = parseInt(ts/60);
secondLeft = ts - minuteLeft * 60;
}
if(hourLeft < 10) hourLeft = '0' +hourLeft;
if(minuteLeft < 10) minuteLeft = '0' +minuteLeft;
if(secondLeft<10) secondLeft='0'+secondLeft;
if( dateLeft > 0 )
dateLeft = dateLeft + "天" ;
else
dateLeft = "";
if( hourLeft > 0 )
hourLeft = hourLeft + "小时" ;
else
{
if( dateLeft != "" )
hourLeft = "00小时";
else
hourLeft = "";
}
if( minuteLeft > 0 )
minuteLeft = minuteLeft + "分钟" ;
else
{
if( dateLeft !="" || hourLeft != "")
minuteLeft = "00分钟";
else
minuteLeft = "";
}
if( secondLeft > 0 )
secondLeft = secondLeft + "秒" ;
else
{
if( dateLeft !="" || hourLeft != "" || minuteLeft != "")
secondLeft = "00秒";
else
secondLeft = "";
}
if (dateLeft == '') {
Temp=dateLeft+hourLeft+minuteLeft+secondLeft ;
}else {
Temp=dateLeft+hourLeft;
}
if(dateLeft <=0 && hourLeft<=0 && minuteLeft<=0 && secondLeft <=0)
{
Temp = "成交结束";
stopclock();
}
if (document.getElementById('time2')) document.getElementById('time2').innerHTML=Temp;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function stopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function macauclock()
{
stopclock();
showtime();
}
function onloadall()
{
macauclock();
try
{
initprovcity();
}
catch(e)
{
}
}
try
{
onload=onloadall();
}
catch(e)
{
}
</SCRIPT>
生成页面的时候把剩余的秒数写在<font id="time2">18595</font>里面就可以了。
2、 function go()
{
//
// nowTime
//
now=new Date();
var Time="";
var h=now.getHours();
Time=h+":";
var m=now.getMinutes()
if(m<10)
Time=Time+"0"+m+":";
else
Time+=m+":";
var s=now.getSeconds();
if(s<10)
Time=Time+"0"+s;
else
Time+=s;
document.Form1.nowTime.value=Time;
//
// leave time 70mintes, ||have 00:17:34,leave 00:52:26||have 17:00,leave 53:00||00:5:14--->01:04:46
// 还要考虑小时
//
time = (now.getTime() - start.getTime()) / 1000;
time = Math.floor( time);//去掉小数位数,保留整数
//
//00:00:00的情况,就是剩余的时间要大于等于examTime
//
if(time>=examTime*60)
{
alert("考试时间已到!!")
getAunwsers();
}
haveS = time % 60;
haveM = Math.floor( time / 60);
var leaveH;
var leaveM;
var leaveS;
//
if(haveS==0)
{
leaveM=examTime-haveM;
leaveH=Math.floor( leaveM / 60);
if(leaveM<10)
document.Form1.leaveTime.value="0"+leaveH+":"+"0"+leaveM+":00"
else
document.Form1.leaveTime.value="0"+leaveH+":"+leaveM+":00"
}
else
{
leaveS=60-haveS;
if(leaveS<10)
s="0"+leaveS;
else
s=leaveS;
leaveM=examTime-haveM-1;
//
leaveH=Math.floor( leaveM / 60);
if(leaveM<10)
document.Form1.leaveTime.value="0"+leaveH+":"+"0"+leaveM+":"+s;
else
document.Form1.leaveTime.value="0"+leaveH+":"+leaveM+":"+s;
}
setTimeout("go()",1000);
}
//
// setExamTime
//
start=new Date();
//document.Form1.toTime.value是字符类型,需要转换成整形值
var examTime=parseInt(document.Form1.toTime.value,10);
function setExamTime()
{
//
//startTime
//
var Time="";
var h=start.getHours();
Time=h+":";
var m=start.getMinutes()
if(m<10)
Time=Time+"0"+m+":";
else
Time+=m+":";
var s=start.getSeconds();
if(s<10)
Time=Time+"0"+s;
else
Time+=s;
document.Form1.startTime.value=Time;
//这句话不能加,不知道为什么
//document.Form1.toTime.value="分钟";
//
// endTime
//
if(examTime+m>=60)
{
if(h==24)
h=1;
else
h+=1;
m=examTime+m-60;
}
else
{
m=examTime+m
}
//
Time=h+":";
if(m<10)
Time+="0"+m+":";
else
Time+=m+":";
if(s<10)
Time+="0"+s;
else
Time+=s;
document.Form1.endTime.value=Time;
//
//
//
go();
}
function go()
{
//
// nowTime
//
now=new Date();
var Time="";
var h=now.getHours();
Time=h+":";
var m=now.getMinutes()
if(m<10)
Time=Time+"0"+m+":";
else
Time+=m+":";
var s=now.getSeconds();
if(s<10)
Time=Time+"0"+s;
else
Time+=s;
document.Form1.nowTime.value=Time;
//
// leave time 70mintes, ||have 00:17:34,leave 00:52:26||have 17:00,leave 53:00||00:5:14--->01:04:46
// 还要考虑小时
//
time = (now.getTime() - start.getTime()) / 1000;
time = Math.floor( time);//去掉小数位数,保留整数
//
//00:00:00的情况,就是剩余的时间要大于等于examTime
//
if(time>=examTime*60)
{
alert("考试时间已到!!")
getAunwsers();
}
haveS = time % 60;
haveM = Math.floor( time / 60);
var leaveH;
var leaveM;
var leaveS;
//
if(haveS==0)
{
leaveM=examTime-haveM;
leaveH=Math.floor( leaveM / 60);
if(leaveM<10)
document.Form1.leaveTime.value="0"+leaveH+":"+"0"+leaveM+":00"
else
document.Form1.leaveTime.value="0"+leaveH+":"+leaveM+":00"
}
else
{
leaveS=60-haveS;
if(leaveS<10)
s="0"+leaveS;
else
s=leaveS;
leaveM=examTime-haveM-1;
//
leaveH=Math.floor( leaveM / 60);
if(leaveM<10)
document.Form1.leaveTime.value="0"+leaveH+":"+"0"+leaveM+":"+s;
else
document.Form1.leaveTime.value="0"+leaveH+":"+leaveM+":"+s;
}
setTimeout("go()",1000);
}
setExamTime();
-----------------------------------------------------------------
<div id="myleft" style="Z-INDEX: 1; RIGHT: 5px; VISIBILITY: visible; WIDTH: 150px; POSITION: absolute; TOP: 300px">
<table id="setTable" cellSpacing="0" cellPadding="0" width="150" bgColor="#ffffcc" border="0">
<tr>
<td align="center" colSpan="2">钟 表</td>
</tr>
<tr>
<td width="65">开始时间:</td>
<td width="85"><input readOnly type="text" size="10" name="startTime"></td>
</tr>
<tr>
<td>结束时间:</td>
<td><input readOnly type="text" size="10" name="endTime"></td>
</tr>
<tr>
<td>考试时间:</td>
<td><input id="toTime" readOnly type="text" size="10" name="toTime" runat="server"></td>
<tr>
<td D>现在时间:</td>
<td><input readOnly type="text" size="10" name="nowTime"></td>
</tr>
<tr>
<td D>剩余时间:</td>
<td><input readOnly type="text" size="10" name="leaveTime"></td>
</tr>
<tr>
<td align="center" colSpan="2"><br>
<input id="btnOK" onclick="getAunwsers()" type="submit" value="结束考试">
</td>
</tr>
</table>
</div>