HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

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:

sunriseThe time of the sunrise (zenith angle = 90°35').
sunsetThe time of the sunset (zenith angle = 90°35').
transitThe time when the sun is at its zenith, i.e. has reached its topmost point.
civil_twilight_beginThe start of the civil dawn (zenith angle = 96°). It ends at sunrise.
civil_twilight_endThe end of the civil dusk (zenith angle = 96°). It starts at sunset.
nautical_twilight_beginThe start of the nautical dawn (zenith angle = 102°). It ends at civil_twilight_begin.
nautical_twilight_endThe end of the nautical dusk (zenith angle = 102°). It starts at civil_twilight_end.
astronomical_twilight_beginThe start of the astronomical dawn (zenith angle = 108°). It ends at nautical_twilight_begin.
astronomical_twilight_endThe 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
)