= 5.1.2, PHP 7, PHP 8)date_sun_info — Returns an array with information about sunset/sunrise and twilight begin/end說明date_sun_inf">
(PHP 5 >= 5.1.2, PHP 7, PHP 8)
date_sun_info — Returns an array with information about sunset/sunrise and twilight begin/end
$timestamp, float $latitude, float $longitude): array
timestampUnix timestamp.
latitudeLatitude in degrees.
longitudeLongitude in degrees.
Returns array on success 或者在失敗時(shí)返回 false.
The structure of the array is detailed in the following list:
sunrisesunsettransitcivil_twilight_beginsunrise.
civil_twilight_endsunset.
nautical_twilight_begincivil_twilight_begin.
nautical_twilight_endcivil_twilight_end.
astronomical_twilight_beginnautical_twilight_begin.
astronomical_twilight_endnautical_twilight_end.
The values of the array elements are either UNIX timestamps, false if the
sun is below the respective zenith for the whole day, or true if the sun is
above the respective zenith for the whole day.
示例 #1 A date_sun_info() example
<?php
$sun_info = date_sun_info(strtotime("2006-12-12"), 31.7667, 35.2333);
foreach ($sun_info as $key => $val) {
echo "$key: " . date("H:i:s", $val) . "\n";
}
?>
以上例程會(huì)輸出:
sunrise: 05:52:11 sunset: 15:41:21 transit: 10:46:46 civil_twilight_begin: 05:24:08 civil_twilight_end: 16:09:24 nautical_twilight_begin: 04:52:25 nautical_twilight_end: 16:41:06 astronomical_twilight_begin: 04:21:32 astronomical_twilight_end: 17:12:00
示例 #2 Polar night
<?php
var_dump(date_sun_info(strtotime("2017-12-21"), 90, 0));
?>
以上例程會(huì)輸出:
array(9) {
["sunrise"]=>
bool(false)
["sunset"]=>
bool(false)
["transit"]=>
int(1513857490)
["civil_twilight_begin"]=>
bool(false)
["civil_twilight_end"]=>
bool(false)
["nautical_twilight_begin"]=>
bool(false)
["nautical_twilight_end"]=>
bool(false)
["astronomical_twilight_begin"]=>
bool(false)
["astronomical_twilight_end"]=>
bool(false)
}
示例 #3 Midnight sun
<?php
var_dump(date_sun_info(strtotime("2017-06-21"), 90, 0));
?>
以上例程會(huì)輸出:
array(9) {
["sunrise"]=>
bool(true)
["sunset"]=>
bool(true)
["transit"]=>
int(1498046510)
["civil_twilight_begin"]=>
bool(true)
["civil_twilight_end"]=>
bool(true)
["nautical_twilight_begin"]=>
bool(true)
["nautical_twilight_end"]=>
bool(true)
["astronomical_twilight_begin"]=>
bool(true)
["astronomical_twilight_end"]=>
bool(true)
}