最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - js - Stop after 1 hour - Stack Overflow

programmeradmin3浏览0评论

I was creating a program which should stop automatically a <b>. So please tell me how, here is a little bit I am thinking off:

var time = date.getTime();
var seconds = 0;
if (time + seconds == date.getTime())
{
// Stop everything i do by myself :)
}

I was creating a program which should stop automatically a <b>. So please tell me how, here is a little bit I am thinking off:

var time = date.getTime();
var seconds = 0;
if (time + seconds == date.getTime())
{
// Stop everything i do by myself :)
}
Share Improve this question edited Dec 18, 2017 at 16:47 vinS 1,4755 gold badges25 silver badges39 bronze badges asked Feb 10, 2017 at 15:44 modifyermodifyer 671 gold badge2 silver badges7 bronze badges 2
  • use a setTimeout. – Daniel A. White Commented Feb 10, 2017 at 15:45
  • Yes but i dont want to use this ;) – modifyer Commented Apr 14, 2017 at 12:50
Add a ment  | 

2 Answers 2

Reset to default 5

Something like this:

var keepGoing = true;


setTimeout(function(){

    keepGoing = false;

}, 1000 * 60 * 60); //one hour


while(keepGoing){

    //stuff to do

}

We can use a bination of setInterval and setTimeout to acplish this.

function doStuff(){
    //do whatever you need to do
}

var is_running = true;

setTimeout(function(){
    is_running = false; //Stop the program
}, 1000 * 60 * 60); //Do this after 1 hour

while(is_running){
    doStuff(); //whatever your function does
}

发布评论

评论列表(0)

  1. 暂无评论