zoukankan      html  css  js  c++  java
  • js 正计时和倒计时

    showTimeIncrease(){//正计时
    var self = this;
    let count=0;
    self.handle1 = setInterval(() => {
    var hour = 0, minute = 0, second = 0;
    hour=parseInt(count/60/60);
    minute=parseInt(count/60%60);
    second=parseInt(count%60);
    this.html=self.toDouble(hour)+":"+self.toDouble(minute)+":"+self.toDouble(second);
    count++;
    },1000);
    toDouble(num){
    if(num < 10){
    return '0'+ num;
    }else{
    return '' + num;
    }
    }

    remainingTime(years){//倒计时
    var self = this;
    var dateFinal = new Date(years); //设置倒计时到达时间
    var dateNow = new Date(); //获取系统当前时间
    var dateSub = dateFinal - dateNow; //计算差值,单位毫秒
    self.timeHtml = '00天00小时00分钟';
    if(dateSub<=0){
    clearInterval(self.intervalDelete);
    return;
    }
    var day = hour = minute = second = dayBase = hourBase = minuteBase = secondBase = 0; //初始化各个数值
    dayBase = 24 * 60 * 60 * 1000; //计算天数的基数,单位毫秒。1天等于24*60*60*1000毫秒
    hourBase = 60 * 60 * 1000; //计算小时的基数,单位毫秒。1小时等于60*60*1000毫秒
    minuteBase = 60 * 1000; //计算分钟的基数,单位毫秒。1分钟等于60*1000毫秒
    secondBase = 1000; //计算秒钟的基数,单位毫秒。1秒钟等于1000毫秒
    day = Math.floor(dateSub / dayBase); //计算天数,并取下限值。如 5.9天 = 5天
    hour = Math.floor(dateSub % dayBase / hourBase); //计算小时,并取下限值。如 20.59小时 = 20小时
    minute = Math.floor(dateSub % dayBase % hourBase / minuteBase); //计算分钟,并取下限值。如 20.59分钟 = 20分钟
    //当天数小于等于0时,就不用显示
    if(day <= 0){
    self. timeHtml = self.toDouble(hour) + '小时' +self.toDouble(minute) + '分钟';
    }else{
    self.timeHtml = day + '天' + self.toDouble(hour) + '小时' + self.toDouble(minute) + '分钟';
    }

    }
  • 相关阅读:
    动态类型
    unlink与close关系
    Google 历年笔试面试30题
    UNIX网络编程 卷2 源代码使用
    centos安装telnet
    python中安装第三方模块
    Linux平台 Oracle 18c RAC安装Part1:准备工作
    RHEL7 配置iSCSI模拟环境
    Solaris 10主机名和IP地址步骤
    设置sqlplus不显示除查询结果外的信息
  • 原文地址:https://www.cnblogs.com/susuhyc/p/6899994.html
Copyright © 2011-2022 走看看