js倒计时----小功能记录

结合上一篇时间转换,在记录一个倒计时。

$(function () {
    //将时间转化为时间戳
    var noHis = "2020-03-17 12:15:55";//结束时间
    var starttime = "2020-02-20 12:00:00";//开始时间

    var oNoHis = $.myTime.DateToUnix(noHis);//转换成结束时间戳
	
    var startoNoHis = $.myTime.DateToUnix(starttime);//转换为开始时间戳
	
	var timestamp = Date.parse(new Date())/1000; //本地时间戳
    // var timestamp = _NOW_TIME;//服务器时间
    console.log(oNoHis, timestamp);
    var intDiff = parseInt(oNoHis - timestamp);//倒计时总秒数量
	console.log(intDiff+"intDiff")
    function timer(intDiff)  {
        if ((startoNoHis > timestamp) || (timestamp > oNoHis)) {
            $('.Countdown_xf').hide();
			console.log(1)
        } else {
			console.log(2)
			var html = '<div class="Countdown_xf">'+
							'<p class="count_txt">Countdown</p>'+
							'<div class="count_time">'+
								'<p class="count_day" id="count_day">0</p>'+
								'<span class="count_risk">:</span>'+
								'<p class="count_hour" id="count_hour">00</p>'+
								'<span class="count_risk">:</span>'+
								'<p class="count_minute"id="count_minute">00</p>'+
								'<span class="count_risk">:</span>'+
								'<p class="count_second" id="count_second">00</p>'+
							'</div>'+
						'</div>';
            $('.xfans_Countdown').html(html);
            window.setInterval(function () {

                var day = 0,

                    hour = 0,

                    minute = 0,

                    second = 0;//时间默认值

                if (intDiff > 0) {

                    day = Math.floor(intDiff / (60 * 60 * 24));

                    hour = Math.floor(intDiff / (60 * 60)) - (day * 24);

                    minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);

                    second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);

                }
                if (day <= 9) day = '0' + day;
                if (hour <= 9) hour = '0' + hour;
                if (minute <= 9) minute = '0' + minute;

                if (second <= 9) second = '0' + second;

                $('#count_day').html(day);

                $('#count_hour').html('<s id="h"></s>' + hour);

                $('#count_minute').html('<s></s>' + minute);

                $('#count_second').html('<s></s>' + second);
				
                intDiff--;
            }, 1000);
            $('.xfans_Countdown').show();
        }
    }
	timer(intDiff);
})

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值