基本的に私はJavaScriptが得意で、プロジェクトのカウントダウンタイマーを改善したいと思っています。現時点では、私のタイマーは次のようになっています。
01:25:05
私はそれをこのように見せたいです:
1時間25分5秒
しかし、私もそれを賢くしたいと思っています。したがって、わずか25分であれば、次のようになります。
25分。
これは私の現在のjavascriptコードです:
function secondCountdown(){
if(typeof(skip) == "undefined"){
skip = "set";
} else {
var timeleft = document.getElementById("timeleft").innerHTML;
var time_split = timeleft.split(":");
if(parseInt(time_split[0]) < 10){
time_split[0] = time_split[0].charAt(1);
}
if(parseInt(time_split[1]) < 10){
time_split[1] = time_split[1].charAt(1);
}
if(parseInt(time_split[2]) < 10){
time_split[2] = time_split[2].charAt(1);
}
seconds = parseInt(time_split[2]) + parseInt(time_split[1]*60) + parseInt(time_split[0]*3600);
seconds -= 1;
if(seconds > 0){
var hours= Math.floor(seconds/3600);
seconds %= 3600;
var minutes = Math.floor(seconds/60);
seconds %= 60;
var timeleft = ((hours < 10) ? "0" : "") + hours + ":" + ((minutes < 10) ? "0" : "") + minutes + ":" + ((seconds < 10) ? "0" : "") + seconds;
document.getElementById("timeleft").innerHTML = timeleft;
} else {
document.getElementById("timeleft").innerHTML = "";
window.location='test.php?pageid=' + getURLParam("pageid");
return false;
}
}
setTimeout("secondCountdown()",1000);
}
window.onload = secondCountdown;
多分誰かが私のためにそれを編集して私が望むものを出力させることができますか?
編集:
これはタイマーのPHP側です。
<span id="timeleft">
$master = $timer['gta_time'] - time();
echo date( "00:i:s", $timer['gta_time'] - time() );
</span>