zoukankan      html  css  js  c++  java
  • JS实现简单倒计时

    
    
    /*倒计时*/
    lcf.downTime =  function (endTime,obj,callback){
        /*基本判断*/
        if(!endTime || typeof endTime !== "string") return false;
        /*基本判断*/
        if(!obj || typeof obj !== "object") return false;
        /*获取日期的毫秒*/
        var endTime = Date.parse(endTime);
        /*定时器*/
       var timer = setInterval(function () {
            var nowTime  = +new Date();
            /*2个时间的差 毫秒*/
            var minus =endTime - nowTime;
            /*相差的天数*/
            var day = parseInt(minus/1000/60/60/24);
            /*相差的小时*/
            var hours = parseInt(minus/1000/60/60%24);
            /*相差的分钟*/
            var mintue = parseInt(minus/1000/60%60);
            /*获取相差的秒*/
            var second = parseInt(minus/1000%60);
            if(minus<=0){
                clearInterval(timer);
                day =0;
                hours =0;
                mintue =0;
                second =0;
            }else{
                obj[0].innerHTML = parseInt(hours/10);
                obj[1].innerHTML = hours%10;
                obj[3].innerHTML = parseInt(mintue/10);
                obj[4].innerHTML = mintue%10;
                obj[6].innerHTML = parseInt(second/10);
                obj[7].innerHTML = second%10;}
        },1000);
    
        callback && callback();
    };
    View Code
    
    
    
    /*倒计时*/
    lcf.downTime =  function (endTime,obj,callback){
        /*基本判断*/
        if(!endTime || typeof endTime !== "string") return false;
        /*基本判断*/
        if(!obj || typeof obj !== "object") return false;
        /*获取日期的毫秒*/
        var endTime = Date.parse(endTime);
        /*定时器*/
       var timer = setInterval(function () {
            var nowTime  = +new Date();
            /*2个时间的差 毫秒*/
            var minus =endTime - nowTime;
            /*相差的天数*/
            var day = parseInt(minus/1000/60/60/24);
            /*相差的小时*/
            var hours = parseInt(minus/1000/60/60%24);
            /*相差的分钟*/
            var mintue = parseInt(minus/1000/60%60);
            /*获取相差的秒*/
            var second = parseInt(minus/1000%60);
            if(minus<=0){
                clearInterval(timer);
               return false;
            }else{
                obj[0].innerHTML = parseInt(hours/10);
                obj[1].innerHTML = hours%10;
                obj[3].innerHTML = parseInt(mintue/10);
                obj[4].innerHTML = mintue%10;
                obj[6].innerHTML = parseInt(second/10);
                obj[7].innerHTML = second%10;}
        },1000);
    
        callback && callback();
    };
  • 相关阅读:
    告别零码软件
    win+mingw+libxml2试用笔记
    beacon with java 1.7 on fedora
    mininet指令详解
    java Socket完美实例
    gnome3 下 qt 应用极其丑陋的解决方案
    org.apache.log4j Class Level
    Mac如何修改文本文件编码
    unity性能优化相关
    平面图判定
  • 原文地址:https://www.cnblogs.com/lcf1314/p/5679820.html
Copyright © 2011-2022 走看看