时间戳转换为天/时/分

308 阅读1分钟
data () {
        return {
            examinationOpeningTime: '', // 开始时间
            examinationClosingTime: '', // 结束时间
            timeRemain: 0, // 剩余时间
            day: 0, // 天
            hour: 0, // 时
            minute: 0, // 分
            timer: null // 定时器
        };
  watch: {
        timeRemain (newVal) {
            if (newVal) {
                let day = parseInt(newVal / (60 * 60 * 24 * 1000)); // 当前所剩天数
                let hour = parseInt((newVal - day * 60 * 60 * 24 * 1000) / (60 * 60 * 1000)); // 当前所剩小时数
                let minute = parseInt((newVal - day * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000) / (60 * 1000)); // 当前所剩分钟数
                this.day = day;
                this.hour = hour;
                this.minute = minute;
            }
        }
    },
        beforeDestroy() {
            clearInterval(this.timer);
        },
   methods:{
       setCountDown () {
            this.timer = setInterval(() => {
                this.timeRemain -= 60 * 1000;
                if (this.timeRemain <= 0) {
                    clearInterval(this.timer);
                    this.timeRemain = 0;
                    this.personCondition = 2;
                    this.statusUrl = require('../../assets/images/examination/image4.png');
                }
            }, 60 * 1000);
        },
   }