我使用这个倒计时脚本,每天倒计时到下午 5 点。如何在没有秒的情况下打印时间?
<?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;
}
?>