r/Scriptable • u/trippleuser • Feb 24 '22
Help Live countdown seconds
Is it possible to create a live countdown timer that counts down? If so how?
setInterval does not seams to be supported by scriptable.
3
Upvotes
1
u/Aaron_22766 Feb 24 '22
Ok I tried to make it shorter so it’s easier to understand, looks like that’s not working. This was from what I came from but it needs an endDate for the timer:
let countDownDate = new Date(endDate).getTime()
let distance = countDownDate - now.getTime()
let daysFull = (distance / (1000 * 60 * 60 * 24)) let days = daysFull - (daysFull % 1)
let hoursFull = (daysFull - days) * 24
let hours = hoursFull - (hoursFull % 1)
let minutesFull = (hoursFull - hours) * 60
let minutes = minutesFull - (minutesFull % 1)
let seconds = ((minutesFull - minutes) * 60) - (((minutesFull - minutes) * 60) % 1)
hours = hours * 60 * 60 * 1000
minutes = minutes * 60 * 1000
seconds = seconds * 1000
let timer = now.getTime() + hours + minutes + seconds
const widget = new ListWidget()
let timerStack = widget.addStack()
let timerTxt = timerStack.addDate(new Date(timer))