美文网首页
js显示倒计时,时间戳转日期,日期转时间戳

js显示倒计时,时间戳转日期,日期转时间戳

作者: 小进我是爸爸 | 来源:发表于2020-08-12 21:04 被阅读0次
 $('span').siblings('.gtime').each(function () {
        var strtime = $(this).attr('data-time');
        var date = new Date(strtime);
        time1 = date.getTime()+{$chaoshi}*1000;
         console.log(new Date().getTime());
        xtime=getRandomCode(time1,$(this))


    })
    function getRandomCode(xtime,obj) {
        if ((xtime-(new Date()).getTime()) <= 0) {

            var url="{:url('goods/fenghao1')}";
            var buyid =obj.parent().attr('id');
            // alert(buyid);
            $.ajax({
                type: "post",
                url: url,
                data: {id:buyid},
                dataType: "json",
                success: function (data) {
                    console.log('封号了');
                }
            })
            obj.text('超时了');
        } else {
            xtime-=1000;
            ytime=parseInt((xtime-(new Date()).getTime())/60000)
            obj.text(ytime+'分钟');
        }

        setTimeout(function () {
            getRandomCode(xtime,obj);
        }, 1000);


    }
    function timestampToTime(timestamp) {
        var date = new Date(timestamp );//时间戳为10位需*1000,时间戳为13位的话不需乘1000
     //   var Y = date.getFullYear() + '-';
     //   var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
       // var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var s = date.getSeconds();
        return h+m+s;
    }

相关文章

网友评论

      本文标题:js显示倒计时,时间戳转日期,日期转时间戳

      本文链接:https://www.haomeiwen.com/subject/zyamdktx.html