JS 时间显示效果代码分分快三计划

作者:分分快三计划
        let time = setInterval(() => {
            if (this.flag == true) {
                clearInterval(time)
            }
            this.timeDown()
        }, 100)
    },
    timeDown() {
        const endTime = new Date(this.settime);
        const nowTime = new Date();
        let leftTime = parseInt((endTime.getTime() - nowTime.getTime()) / 1000);
        let d = parseInt(leftTime / (24 * 60 * 60));
        let h = this.formate(parseInt(leftTime / (60 * 60) % 24));
        let m = this.formate(parseInt(leftTime / 60 % 60));
        let s = this.formate(parseInt(leftTime % 60));
        if (leftTime <= 0) {
            this.flag = true;
            alert("时间到,停止作答");
        }
        this.keepTime = `${h}:${m}:${s}`;
    },
    formate(time) {
        if (time >= 10) {
            return time
        } else {
            return `0${time}`
        }
    },

function SetTime(NomeTime)
{
document.getElementById("TimeValue").innerHTML=NomeTime "秒后自动登录";
NomeTime--;
if(NomeTime==-1)
{
document.getElementById("TimeValue").style.display="none";
return;
}
window.setTimeout("javascript:SetTime(" NomeTime ")",1000);
}

}

其中NomeTime为初始时间大小比如10秒!

export default {
data() {
return {
keepTime: '倒计时',
limittime:100,
settime: '',
flag: false
}
},
methods: {
StartCountDown() {
var mydate = new Date();
mydate.setMinutes(mydate.getMinutes() this.limittime);
this.settime=mydate;

代码如下: function settime() { var myyear,mymonth,myweek,myday,mytime,mymin,myhour,mysec; var mydate=new Date(); myyear=mydate.getFullYear(); mymonth=mydate.getMon...

<el-button type="text" v-text="keepTime" @click="StartCountDown">

function settime()
{
var myyear,mymonth,myweek,myday,mytime,mymin,myhour,mysec;
var mydate=new Date();
myyear=mydate.getFullYear();
mymonth=mydate.getMonth();
myday=mydate.getDate();
myhour=mydate.getHours();
mymin=mydate.getMinutes();
mysec=mydate.getSeconds();
mytime="今天是:" myyear "年" mymonth "月" myday "日" myhour ":" mymin ":" mysec;
document.getElementById('xwgtime').innerHTML=mytime;
setTimeout('settime()',1000);
}

项目需要做一个考试倒计时的功能,参考了CSDN上的一遍博文,做出自己的功能,在此谢谢sinat_17775997
```

复制代码 代码如下:

这样就能显示时间了!脚本真的很强大。。。!用该方法也可以做出网站过几少后自己转换到时另一个页面去的功能!
例如:

复制代码 代码如下:

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划