J
J
jamster2018-02-14 18:49:23
JavaScript
jamster, 2018-02-14 18:49:23

SetInertval every day?

Good evening, please help me how to implement setInterval every day. Or every new day?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2018-02-14
@jamster

Something like this:
https://jsfiddle.net/n08mo1v3/8/

function checkTime() {
  const now = Date.now()
  const time = localStorage.getItem('timestamp') || null
  if (time) {
    if (Number(now) - Number(time) >= 1000 * 60 * 60 * 24) {
      console.log('Function called')
      localStorage.setItem('timestamp', now)
    }
  } else {
    localStorage.setItem('timestamp', now)
  }
}

setInterval(checkTime, 1000 * 60)

D
Deodatuss, 2018-02-14
@Deodatuss

store the date of the last event in localstorage and check it in setInterval

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question