In this article, you will learn how to get the sun information in PHP. The date_sun_info() function returns the sunrise/sunset or twilight start/end of the specified date.
What is the syntax of the date_sun_info() function in PHP?
date_sun_info(timestamp, latitude, longitude)
Parameter | Description |
---|---|
timestamp | Timestamp to get the information of – Required |
latitude | Latitude of the location in degrees – Required |
longitude | Longitude of the location in degrees – Required |
Examples of the date_sun_info() function
Example 1. In this example, we return the information about the sunrise/sunset and start/end of twilight for the specified date.
<?php
$info=date_sun_info(strtotime("2014-11-15"),31.7667,35.2333);
foreach ($info as $key=>$val)
{
echo "$key: " . date("H:i:s",$val) . " ";
}
?>