根据总秒数,js展示倒计时时分秒

1、根据后端的返回的总秒数据,然后把秒转成时分秒倒计时

 setClock:function(time){
            	var that=this, sec= parseInt(time) , clockCount={}, strTimer="";
            	    clockCount=setInterval(function(){
            	    	if(sec==0){
		                        $(".js-count-down").html("活动已经结束");
		                       clearInterval(clockCount);
		                       return false;
                        }
					    strTimer = that.secondToDate(sec);
					    $(".js-count-down").html(strTimer);
					    sec--;
                    },1000)
            },
secondToDate:function(result){
            	var h = Math.floor(result / 3600) < 10 ? '0'+Math.floor(result / 3600) : Math.floor(result / 3600);
			    var m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
			    var s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
			        if(h==0){
			        	result = m + ":" + s;
			        }else{
			        	result = h+':'+m + ":" + s
			        }
			    return result;
 },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章