How to call a function every hour?

后端 未结 5 1016
轻奢々
轻奢々 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:10

    EDIT: Oops, I didn't see the " o' clock" things, so I edit my answer :

    var last_execution = new Date().getTime();
    function doSomething(force){
      var current_time = new Date().getTime();
      if (force || (current_time.getMinutes() == 0)
      {
        last_execution = current_time;
        // something
        // ...
      }
      setTimeout(doSomething(false), 1000);
    }
    // force the first time
    doSomething(true); 
    

提交回复
热议问题