我有这段代码可以获取今天日期的日出和日落时间。
代码是:
<?php
function miltoampm($hour) {
$mins = substr($hour,-2);
$ampm = ($hour >=12 && $hour <24) ? "PM" : "AM";
$newhour = ($hour % 12 === 0) ? 12 : $hour % 12;
return $newhour . ':' . $mins . " " . $ampm;
}
//Calculate the sunrise and sunset time
//Latitude: 41.81
//Longitude: -87.68
//Zenith ~= 90
//offset: -5 GMT is Chicago
$sunriseTime = (date_sunrise(time(),SUNFUNCS_RET_STRING,41.8119,-87.6873,90,-5)); //Sunrise Time
$sunsetTime = (date_sunset(time(),SUNFUNCS_RET_STRING,41.8119,-87.6873,90,-5)); //Sunset Time
?>
现在我想这样做,但我真的不知道如何:
If current time is anywhere from $sunrise and less then $sunset then
$Img = "sun.png";
else
$Img = "noon.png";
end if