我不認爲PHP在這裏是正確的工具。聽起來像Javascript可能是你想要的,如果你想在你的屏幕上顯示這個。
對於PHP,你可以使用日期函數
function secondsToWebvtt($seconds) {
//set the time to midnight (the actual date part is inconsequential)
$time = mktime(0,0,0,1,2,2012);
//add the number of seconds
$time+= $seconds;
//return the time in hh:mm:ss.000 format
return date("H:i:s.000",$time);
}
使用JavaScript,我會用這樣的函數
var seconds = 0;
function toTime() {
var time = new Date("1/1/2012 0:00:00");
var newSeconds = time.getSeconds() + seconds;
var strSeconds = newSeconds + "";
if(strSeconds.length < 2) { strSeconds = "0" + strSeconds; }
var hours = time.getHours() + "";
if(hours.length < 2) { hours = "0" + hours; }
var minutes = time.getMinutes() + "";
if(minutes.length < 2) { minutes = "0" + minutes; }
var dispTime = hours + ":" + minutes + ":" + strSeconds + ".000";
return dispTime;
}
function getTime() {
var time = toTime(seconds);
//do something with time here, like displaying on the page somewhere.
seconds++;
}
然後用setInterval來調用函數
setInterval("getTime",1000);
我不確定你的問題是否清楚...... – zavg
如果你打算通過PHP更新工具提示,你可能會從錯誤的角度來看待這個問題。 PHP是服務器端的,你需要用Javascript來更新工具提示。 – Fiarr
@ Fiarr nope,我不更新工具提示,我需要在php文件中循環計時器。例如:for($ i = 0; $ i <7200; $ i ++){} – richard