2017-05-27 26 views
-5

我想創建一個函數/ ALG根據時間執行一個腳本。 這不會與PHP的'睡眠'功能(我已經嵌套循環頭和嘗試)。我需要一個運行計時器和檢查器

這裏是我要求完成的邏輯:

$time= time(); // checks time 

if($time == 3'o'clock) { 
    do_something(); 
} else { 
    check_time(); 
    and_keep_counting(); 
} 

我需要一個連續的時鐘滴答|它可以同時在後臺運行 ,連續檢查時鐘。 我可能要去jquery?

+3

認真完善你使用的語言太俚語 – mdarmanin

+2

你也不需要使用褻瀆的話;我不得不[編輯](https://stackoverflow.com/revisions/44220851/2)很多東西。這樣的語言可能被標記爲粗魯/冒犯。 –

+1

我希望你已經閱讀並理解^ –

回答

1

這會不會是非常有效的,但會做的伎倆:

(function time(){ 
 
    var t = new Date().toLocaleTimeString(); 
 
    console.log(t); 
 
    if(t === "3:00:00 PM"){ 
 
    // Do whatever you need to here 
 
    runStuff(); 
 
    } 
 
    
 
    // Call the function again in 59 seconds 
 
    setTimeout(time, 59000); 
 
}()); 
 

 
function runStuff(){ 
 
    alert("Time's Up!"); 
 
}

+0

THanx Scotty! - 我需要的只是一個推動 – supadopecat

+2

不客氣......而且,這是斯科特,而不是斯科蒂。 ;) –

+1

@ScottMarcus現在是Scotty。 ;) –

0

我不完全知道你是問什麼,但你可以做這樣的事情有JavaScript的...

var date = new Date();它創建了一個日期時間對象

var hours = date.getHours();它得到的「軍用時間」格式的時間,這意味着1日上午1:00和13日下午1:00

如果你想檢查它是否是三點鐘,你可以做

if (hours == 15) { 
    someFunction(); 
} else { 
    doSomeOtherFunction(); 
} 
相關問題