How to call a function every hour?

后端 未结 5 1092
轻奢々
轻奢々 2021-02-07 09:30

I am trying to update information from a weather service on my page. The info should be updated every hour on the hour. How exactly do I go about calling a function on the hour

5条回答
  •  耶瑟儿~
    2021-02-07 10:17

    Here is what should work (JSFiddle):

    function tick() {
      //get the mins of the current time
      var mins = new Date().getMinutes();
      if (mins == "00") {
        alert('Do stuff');
      }
      console.log('Tick ' + mins);
    }
    
    setInterval(tick, 1000);

提交回复
热议问题