カウントダウンコードは秒まで正確です

27046 ワード

<div id="TimeCounter" style="border:1px solid black;margin:1px;padding:2px;width:300px"></div>

<SCRIPT language=javascript>

<!--

function show_date_time(){

 window.setTimeout("show_date_time()", 1000);

 target=new Date(2008,8,8,20,00,00);

 today=new Date();

 timeold=(target.getTime()-today.getTime());

 

 sectimeold=timeold/1000

 secondsold=Math.floor(sectimeold);

 msPerDay=24*60*60*1000

 e_daysold=timeold/msPerDay

 daysold=Math.floor(e_daysold);

 e_hrsold=(e_daysold-daysold)*24;

 hrsold=Math.floor(e_hrsold);

 e_minsold=(e_hrsold-hrsold)*60;

 minsold=Math.floor((e_hrsold-hrsold)*60);

 seconds=Math.floor((e_minsold-minsold)*60);

 

  if (daysold<0) {

 document.getElementByIdx_x_x("TimeCounter").innerHTML=" , ";

}

 else{

 if (daysold<10) {daysold="0"+daysold}

 if (daysold<100) {daysold="0"+daysold}

 if (hrsold<10) {hrsold="0"+hrsold}

 if (minsold<10) {minsold="0"+minsold}

 if (seconds<10) {seconds="0"+seconds}

 if (daysold<3) {

  document.getElementByIdx_x_x("TimeCounter").innerHTML=" "+daysold+" "+hrsold+" "+minsold+" "+seconds+" ";

}

 else

  document.getElementByIdx_x_x("TimeCounter").innerHTML=" " + daysold+" "+hrsold+" "+minsold+" "+seconds+" ";

}

}

show_date_time();

//-->

</SCRIPT></div>

 

*************************** ***************************************

 

<span id="span_dt_dt" style='border:1px solid black;background-color:#FFFFFF' ></span>

<script language=javascript>

<!--

function show_student163_time(){

window.setTimeout("show_student163_time()", 1000);

BirthDay=new Date("2010/11/02 11:55:00");// 

today=new Date();

timeold=(BirthDay.getTime()-today.getTime());

sectimeold=timeold/1000

secondsold=Math.floor(sectimeold);

msPerDay=24*60*60*1000

e_daysold=timeold/msPerDay

daysold=Math.floor(e_daysold);

e_hrsold=(e_daysold-daysold)*24;

hrsold=Math.floor(e_hrsold);

e_minsold=(e_hrsold-hrsold)*60;

minsold=Math.floor((e_hrsold-hrsold)*60);

seconds=Math.floor((e_minsold-minsold)*60);

if(daysold>=0&&hrsold>=0&&minsold>=0&&seconds>0)

{

span_dt_dt.innerHTML=daysold+" "+hrsold+" "+minsold+" "+seconds+" " ;

}

else

{

 location.href="http://www.baidu.com/";

}

}

show_student163_time();

//-->

</script>