我正在创建一个应该自动停止的程序<b>
。所以请告诉我如何,这是我正在考虑的一点:
var time = date.getTime();
var seconds = 0;
if (time + seconds == date.getTime())
{
// Stop everything i do by myself :)
}
我正在创建一个应该自动停止的程序<b>
。所以请告诉我如何,这是我正在考虑的一点:
var time = date.getTime();
var seconds = 0;
if (time + seconds == date.getTime())
{
// Stop everything i do by myself :)
}
像这样的东西:
var keepGoing = true;
setTimeout(function(){
keepGoing = false;
}, 1000 * 60 * 60); //one hour
while(keepGoing){
//stuff to do
}
我们可以使用setInterval
和的组合setTimeout
来实现这一点。
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
}