Answer the question
In order to leave comments, you need to log in
How to stop the timer when it reaches 00:00:00 and start counting 'up'?
Good day to all! I need to implement a timer that counts back the time difference obtained by subtracting the Set Time (in the format DD.MM.YY hh:mm:ss) and the Current Time (in the same format) and when it counts down to 00:00:00 , then you need it to count already 'up'. How to implement 'stop' and countdown 'up'
<div class="green--text" v-if="operation.idle_el === 1" v-html="getDiff()"></div>
data () {
return {
moment: moment.locale('ru'),
diff: null,
startTime: null,
endTime: moment('20.08.19 17:50:00', 'DD.MM.YY HH:mm:ss').format('LTS')
}},
methods: {
getDiff () {
this.diff = moment.utc(moment.duration(this.endTime) - moment.duration(this.startTime)).format('LTS')
console.log(this.diff)
// return '<div>' + this.diff + '</div>'
return this.diff
},
updateCurrentTime () {
this.startTime = moment().format('LTS')
}
},
created () {
this.startTime = moment().format('LTS')
setInterval(() => this.updateCurrentTime(), 1 * 1000)
}
Answer the question
In order to leave comments, you need to log in
It's easier to adapt a ready-made fareez.info/blog/countdown-timer-using-vuejs .
To determine whether the timer is positive or negative, simply count
computed: {
isNegative() {
return ((this.now - this.date) / 60000) < 0;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question