2018年10月17日 星期三

PHP的時間轉換

👉利用 selenium 玩遊戲時,需要設定玩遊戲分鐘數,需要用來換算及執行動作

✅利用 time() 來取得現在時間(秒),在加上要玩的秒數,利用 while 迴圈來控制

// 計算結束時間
$finishTime = time() + (int)$seconds;

while (time() < $finishTime) { 
    $action->moveByOffset(round($startBtnX),
        round($startBtnY)); 
    $action->moveToElement($canvas,
        round($startBtnX), round($startBtnY))
        ->click()->perform(); 
    $tester->wait(Parameters::$waitingTime['short']);
}

因為沒有要求很準確的結束,這樣已經可以滿足需求。


沒有留言:

張貼留言