根據總秒數,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;
 },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章