日期:2014-05-16  浏览次数:20511 次

求助:我要做一个团购,要有一个倒计时
但是不知道怎么做。
数据库里存一个结束时间,`c_endtime` int(15) COMMENT '

我在网上找了一些源码,改改,但是不正确。

JScript code

        this.GetServerTime =function(times,k){
            var d = new Date(times*1000);
            var c = (d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
            var now = new Date();
            var urodz = new Date(c);
            now.setTime(now.getTime()+250);
            days = (urodz - now) / 1000 / 60 / 60 / 24;
            daysRound = Math.floor(days);
            hours = (urodz - now) / 1000 / 60 / 60 - (24 * daysRound);
            hoursRound = Math.floor(hours);
            minutes = (urodz - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
            minutesRound = Math.floor(minutes);
            seconds = (urodz - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
            secondsRound = Math.round(seconds);
            document.getElementById("time"+k).innerHTML =  "剩余<font>"+daysRound+"</font>天<font>"+hoursRound+"</font>小时";
         }




<span id="time{$k}" class="time"><script> setInterval('Igoods.GetServerTime({$v[c_endtime]},{$k})',250);</script></span>

示出来的时间倒计时是错的,但是不知道怎么改。

------解决方案--------------------
以前用过的一个例子,代码如下:
<html> 
<head> 
<meta name="GENERATOR" content="Microsoft FrontPage 6.0"> 
<meta name="ProgId" content="FrontPage.Editor.Document"> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>Javascript写的倒计时效果代码</title> 
</head> 
<body> 
<script language="javascript" type="text/javascript"> 
var target = new Date(2012, 05, 22, 10, 25, 00).getTime(); 


function show_date_time(){ 
setTimeout("show_date_time()", 1000); 
today=new Date();
timeold = target - 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.getElementById("TimeCounter_0").innerHTML = "生日已经过了"; 
return null;
}
else { 
if (daysold<10) {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.getElementById("TimeCounter_0").innerHTML = "<font color=red>" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒

</font>"; 
}
else {
document.getElementById("TimeCounter_0").innerHTML = daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒"; 



window.onload=sh