我正在尝试在PHP上编写一个代码,当早上6点到下午5点59分之间的时间是早上时,将显示太阳,而下午6点到5点59秒将显示月亮。
到目前为止,这是我的代码:
它总是显示月亮的图像。
<?php
date_default_timezone_set("Asia/Manila");
echo date("l, ");
echo date("d F Y ");
echo date("G:i:sa ");
if (date('G'>17) && ( 'f' >=59) && ('sa' >=59))
{
echo $timeImage = "<img src=sun.png>";
}
else if(date('G'<6) && ('f' <= 01) && ('sa' <= 01 ))
{
echo $timeImage = "<img src=moon.png>";
}
?>
<?php
$seconds = time() - strtotime("today"); //seconds since midnight for now
$sec_a = 6*60*60; //seconds since midnight for 6am
$sec_b = 18*60*60; //seconds since midnight for 6pm
if($seconds >= $sec_a and $sec_b >= $seconds) //current seconds are larger than 6am or equal but smaller than 6pm
{
echo "daytime";
} else {
echo "nighttime";
}