Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

see time left settimeout

// first you can save a timeStamp when you create the timeout
let timerTime = 3600 * 1000 // you can save the timer time on a variable
const timer = setTimeout(() => {
  // do something in future please
}, timerTime)
const timeStamp = Date.now() // with Date.now method you can get the timestamp
// after that you can do somenthing like this
const  getTimeLeft = (timerTime, timeStamp) => {
  const timeLeft = Math.ceil( (timerTime - (Date.now() - timeStamp)) / 60000)
  return timeLeft
}
//Math.ceil round float
//with Date.now -  timeStamp you can calculate how many time has passed since you started the timer until now
//and if you minus that to your timer duration you can obtain how many time is left to the timer to end
//and 60000 is the conversion value to transform it to minutes
Source by newbedev.com #
 
PREVIOUS NEXT
Tagged: #time #left #settimeout
ADD COMMENT
Topic
Name
2+4 =