js倒计时

var endtime=new Date(data.data.voteInfo.voteEndDate.replace(/-/g,'/'));//ios5支持new Date('2013/10/21');这种形式
var nowtime=new Date(data.data.voteInfo.nowDate.replace(/-/g,'/'));
var lefttime=parseInt((endtime.getTime()-nowtime.getTime())/1000);
this._countdown(lefttime)
_countdown:function (lefttime){
      var than=this;
      var d=parseInt(lefttime/(24*60*60));
      var h=parseInt(lefttime/(60*60)%24);
      var m=parseInt(lefttime/60%60);
      var s=parseInt(lefttime%60);
      if(lefttime<=0){
              this.istime=false;
     }else{
              than.time={
                     d:d,
                     h:h,
                     m:m,
                     s:s
              }
               setTimeout(function(){
                        than._countdown(--lefttime);
               },1000);
    }
 },

你可能感兴趣的:(js倒计时)