本帖最后由 wyouyu 于 2012-02-12 19:39:36 编辑

解决方案 »

  1.   

    将目前时间和到期时间用gettime转换成格林威治时间后求出的差在转换成年月天时分秒和毫秒
      

  2.   

    function init(){
    var now=new Date().getTime();
    var endtime=new Date(2012,1,12,20,45,0).getTime();
    var duringtime=endtime-now;
    var day=parseInt(duringtime/86400000);
    var hour=parseInt(duringtime%86400000/3600000);
    var minute=parseInt(duringtime%3600000/60000);
    var seconds=parseInt(duringtime%60000/1000);
    var millseconds=parseInt(duringtime%1000);
    alert(day+"天"+hour+"小时"+minute+"分钟"+seconds+"秒"+millseconds+"毫秒");
    }
    像这样  注意的是new Date(2012,1,12,20,45,0)指的是2012年2月12日20点45分0秒  而不是一月  月份要减一的  呵呵
      

  3.   

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8"/>
    </head>

    <body>
    <div id="show"></div>
    <script>
    var expire, now, countdown, year, month, day, minute, second, buffer;
    expire = "2012/12/24/12:00:00";
    now = new Date();
    countdown = new Date(expire).getTime() - now.getTime();

    buffer = 24 * 60 * 60 * 1000;
    day = Math.floor(countdown / buffer);
    countdown = countdown % buffer;

    buffer = 60 * 1000;
    minute = Math.floor(countdown / buffer);
    countdown = countdown % buffer;

    buffer = 1000;
    second = countdown / buffer;
    countdown = countdown % buffer;

    var str = day + "天" + minute + "分" + second + "秒";
    document.getElementById("show").innerHTML = str;
    </script>
    </body>
    </html>
      

  4.   

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8"/>
    </head>

    <body>
    <div id="show"></div>
    <script>
    var expire = "2012/12/24/12:00:00";

    setInterval(function(){
    var now, countdown, day, minute, second, buffer, string;
    now = new Date();
    countdown = new Date(expire).getTime() - now.getTime();

    buffer = 24 * 60 * 60 * 1000;
    day = Math.floor(countdown / buffer);
    countdown = countdown % buffer;

    buffer = 60 * 1000;
    minute = Math.floor(countdown / buffer);
    countdown = countdown % buffer;

    buffer = 1000;
    second = countdown / buffer;
    countdown = countdown % buffer;

    string = day + "天" + minute + "分" + second + "秒";
    document.getElementById("show").innerHTML = string;
    }, 10);

    </script>
    </body>
    </html>
      

  5.   

    countdown % 60000;
    countdown = Math.floor(countdown / 1000);