WEB/JS

자바스크립트로 타이머 구현하기

나나나나나나나ㅏ나난ㄴ나ㅏ나나 2021. 2. 15. 11:16
728x90
                const _vDate = new Date(new Date().getTime() + 5*60000)
                const _second = 1000
                const _minute = _second * 60
                const _hour = _minute * 60
                const _day = _hour * 60
                let timer

                const _this = this
                setInterval(() => {
                    const now = new Date();
                    const distDt = _vDate - now

                    if(distDt < 0){
                        clearInterval(timer)
                        return ;
                    }

                    const days = Math.floor(distDt / _day)
                    const hours = Math.floor((distDt % _day) / _hour)
                    const min = Math.floor(distDt % _hour / _minute)
                    const sec = Math.floor(distDt % _minute / _second)

                    _this.countDownMin = min
                    _this.countDownSec = sec


                })

 

728x90