jquery 倒计时代码

浏览998
<span style="font-weight: bold;font-size: 20px; " class="time-show">
				<i class="time-houer" style="padding-right:5px">14</i>:<i class="time-minutes">43</i>:<i class="time-seconds">04</i>
				</span>



//秒转化为时分秒的函数转化
		function timetotime(seconds){
			var time_obj={};
			time_obj.hours=0;
			time_obj.minutes=0;
			time_obj.seconds=0;
			if(seconds>60){
				time_obj.minutes=parseInt(seconds/60);
				time_obj.seconds=seconds%60;
			}
			if(time_obj.minutes > 60){
				time_obj.hours = parseInt(time_obj.minutes/60);
				time_obj.minutes= time_obj.minutes % 60;
			}
			if(time_obj.hours < 10){
				time_obj.hours="0"+time_obj.hours
			}
			if(time_obj.minutes < 10){
				time_obj.minutes="0"+time_obj.minutes
			}
			if(time_obj.seconds < 10){
				time_obj.seconds="0"+time_obj.seconds
			}
			return time_obj;
		}
		setInterval(function(){
			var  time_end= "2018-05-11 00:00:00";  //活动结束时间
			var t1 = Date.parse(new Date(time_end.replace(/-/g,'/')));   //new date 可以将一个时间字符串转化为 中国标准时间
			var oDate = new Date();
			var t_now=oDate.getTime();//获取时间戳,一毫秒为单位   php获取时间戳是以秒为单位的
			//获取两者的时间差
			var d=parseInt((t1-t_now)/1000);
			var time_obj=timetotime(d);
			$(".time-houer").html(time_obj.hours);
			$(".time-minutes").html(time_obj.minutes);
			$(".time-seconds").html(time_obj.seconds);
		},1000)

  • 暂无任何回答