title: Set an interval for every 12 hours
body: <p>I need a function to run initially and then to rerun at 12pm and 12am. I'm using VueJS if that has any influence.</p>
  
  <pre><code>fetch_datetime()
  {
      axios.get('/api/core/datetime').then((response) =&gt; {
          this.datetime = response.data;
          this.set_interval();
      });
  },
  
  set_interval()
  {
      var current_date = new Date();
      var hours = current_date.getHours();
      var minutes = current_date.getMinutes();
      var seconds = current_date.getSeconds();
      if(hours == 12 &amp;&amp; minutes == 0 &amp;&amp; seconds == 0 || hours == 0 &amp;&amp; minutes == 0 &amp;&amp; seconds == 0)
      {
          this.fetch_datetime();
      } else
      {
          if(hours &gt;= 12)
          {
              setTimeout(this.fetch_datetime, (1000 * (60 - seconds) * (60 - minutes)) + (1000 * 60 * (24 - hours - 1) * 60));
          } else
          {
              setTimeout(this.fetch_datetime, (1000 * (60 - seconds) * (60 - minutes)) + (1000 * 60 * (12 - hours - 1) * 60));
          }
      }
  </code></pre>
  
  <p>However this isn't working as expected and the function runs early and then runs multiple times on the hour.</p>