每5分钟设置间隔 [英] Setinterval every 5 minutes

查看:853
本文介绍了每5分钟设置间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有JavaScript代码,每隔5分钟将在其中进行一次函数调用.但是我不确定的是,如果我运行该程序的时间是说12.13pm,那么我想在12.15pm调用该函数,然后再调用5分钟,即12.20pm,12.25pm​​ ..... .

我有一个如下所示的javascript:

Hi, I have javascript codes in which I will make a function call every 5 minutes interval. But one thing I am not sure is that, if the time I run the program is let say 12.13pm, then I want to call the function at 12.15pm then the subsequent 5 minutes, meaning 12.20pm, 12.25pm......

I have a javascript which looks like below:

window.setInterval(function ()
{
    MyMethod();
}, 300000);



如何为下午12.15的部分编码?
任何帮助,将不胜感激.谢谢.

我尝试过的事情:

在线研究解决方案,但无济于事.



How can I code for the 12.15pm part?
Any help would be appreciated. Thank you.

What I have tried:

Research online for solution but no avail.

推荐答案

请参见下面的代码

Refer Below Code

window.setInterval(function () {
       var date = new Date();
       alert(date.getMinutes());
       if ((date.getMinutes() % 5) == 0) {

           MyMethod(); // your method
       }
   }, 60000);




检查5分钟的倍数,然后运行方法"MyMethod();"在1分钟的setInterval上.




Check Multiple of 5 Minute''s and run your method " MyMethod();" on a setInterval of 1 Minute.


这篇关于每5分钟设置间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆