date_sun_info
Description
The date_sun_info of Date / Time for PHP returns an array with information about sunset/sunrise and twilight begin/end.
Syntax
date_sun_info ( int $time , float $latitude , float $longitude ) : array
Parameters
time
Timestamp.
latitude
Latitude in degrees.
longitude
Longitude in degrees.
Return
Returns array on success or FALSE on failure. The structure of the array is detailed in the following list:
sunrise | The time of the sunrise (zenith angle = 90°35'). |
sunset | The time of the sunset (zenith angle = 90°35'). |
transit | The time when the sun is at its zenith, i.e. has reached its topmost point. |
civil_twilight_begin | The start of the civil dawn (zenith angle = 96°). It ends at sunrise. |
civil_twilight_end | The end of the civil dusk (zenith angle = 96°). It starts at sunset. |
nautical_twilight_begin | The start of the nautical dawn (zenith angle = 102°). It ends at civil_twilight_begin. |
nautical_twilight_end | The end of the nautical dusk (zenith angle = 102°). It starts at civil_twilight_end. |
astronomical_twilight_begin | The start of the astronomical dawn (zenith angle = 108°). It ends at nautical_twilight_begin. |
astronomical_twilight_end | The end of the astronomical dusk (zenith angle = 108°). It starts at nautical_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.
Examples
1
<? $time = strtotime("2001-02-03"); $latitude = 44.36; $longitude = -110.30; $return = date_sun_info($time, $latitude, $longitude); print_r($return);
Array ( [sunrise] => 981210897 [sunset] => 981246912 [transit] => 981228904 [civil_twilight_begin] => 981209153 [civil_twilight_end] => 981248656 [nautical_twilight_begin] => 981207075 [nautical_twilight_end] => 981250733 [astronomical_twilight_begin] => 981205039 [astronomical_twilight_end] => 981252770 )
2
<? $time = strtotime("2001-02-03"); $latitude = 44.36; $longitude = -110.30; $return = date_sun_info($time, $latitude, $longitude); foreach ($return as $key => $value) { echo "$key: " . date("H:i:s", $value) . PHP_EOL; }
sunrise: 14:34:57 sunset: 00:35:12 transit: 19:35:04 civil_twilight_begin: 14:05:53 civil_twilight_end: 01:04:16 nautical_twilight_begin: 13:31:15 nautical_twilight_end: 01:38:53 astronomical_twilight_begin: 12:57:19 astronomical_twilight_end: 02:12:50
3
<? $time = strtotime("2017-12-21"); $latitude = 90; $longitude = 0; $return = date_sun_info($time, $latitude, $longitude); print_r($return);
Array ( [sunrise] => [sunset] => [transit] => 1513857490 [civil_twilight_begin] => [civil_twilight_end] => [nautical_twilight_begin] => [nautical_twilight_end] => [astronomical_twilight_begin] => [astronomical_twilight_end] => )
4
<? $time = strtotime("2017-06-21"); $latitude = 90; $longitude = 0; $return = date_sun_info($time, $latitude, $longitude); print_r($return);
Array ( [sunrise] => 1 [sunset] => 1 [transit] => 1498046510 [civil_twilight_begin] => 1 [civil_twilight_end] => 1 [nautical_twilight_begin] => 1 [nautical_twilight_end] => 1 [astronomical_twilight_begin] => 1 [astronomical_twilight_end] => 1 )
Links
Date / Time
- checkdate
- date
- date_add
- date_create
- date_create_from_format
- date_create_immutable
- date_create_immutable_from_format
- date_date_set
- date_default_timezone_get
- date_default_timezone_set
- date_diff
- date_format
- date_get_last_errors
- date_interval_create_from_date_string
- date_interval_format
- date_isodate_set
- date_modify
- date_offset_get
- date_parse
- date_parse_from_format
- date_sub
- date_sunrise
- date_sunset
- date_time_set
- date_timestamp_get
- date_timestamp_set
- date_timezone_get
- date_timezone_set
- getdate
- gettimeofday
- gmdate
- gmmktime
- gmstrftime
- idate
- localtime
- microtime
- mktime
- strftime
- strptime
- strtotime
- time
- timezone_abbreviations_list
- timezone_identifiers_list
- timezone_location_get
- timezone_name_from_abbr
- timezone_name_get
- timezone_offset_get
- timezone_open
- timezone_transitions_get
- timezone_version_get