0
我有这段代码可以获取今日日期的日出和日落时间。日出显示图像日落显示不同的人
的代码是:
<?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
甜,伟大工程,但我怎么转换$ sunsetTime或$ sunriseTime(输出例如: '1376651074' )转换为AM/PM格式?因为我想告诉参观者什么时候太阳会出来,什么时候会落下。再次感谢帮助:) – msvuze
这是一个时间戳,所以你可以将它传递给'strftime'。像'strftime(“%r”,$ sunsetTime)'' - 参见[这里是一个完整的参考](http://php.net/manual/en/function.strftime.php)! – jterry