0
我使用這個倒計時腳本,每天倒數到下午5點。如何在沒有秒的情況下打印時間?PHP沒有秒倒計時
<?php
function formatTime($unixtime) {
return date("H:i", $unixtime);
}
function formatSeconds($seconds) {
$time = str_pad(intval(intval($seconds/3600)),2,"0",STR_PAD_LEFT).":"
. str_pad(intval(($seconds/60) % 60),2,"0",STR_PAD_LEFT).":"
. str_pad(intval($seconds % 60),2,"0",STR_PAD_LEFT) ;
return $time;
}
date_default_timezone_set('Europe/Amsterdam');
$hour_in_english = "5pm";
$passed_message = "Bestel nu en je bestelling vertekt morgen!";
$future_message = "Bestel binnen ";
$future_message_2 = " en je bestelling vertrekt vandaag!";
$time_now = strtotime("now");
$time_hour = strtotime("today {$hour_in_english} ");
$difference_in_seconds = $time_hour - $time_now;
if ($difference_in_seconds < 0) {
print $passed_message;
} else {
print $future_message . formatSeconds($difference_in_seconds) . $future_message_2;
}
?>
只是想知道爲什麼你使用PHP,而不是JavaScript? – Ben
不幸的是,我無法在該頁面上使用JavaScript。所以我需要使用PHP – Aduro