Home >>PHP Date Time Functions >PHP date_sun_info() Function
PHP date_sun_info() function is used to returns an array containing information about sunset or sunrise and twilight begin or end, for a specified day and location.
Syntax:
date_sun_info($timestamp, $latitude, $longitude);
Parameter | Description |
---|---|
timestamp | This is a required parameter. This parameter defines a timestamp. |
latitude | This is a required parameter. This parameter defines the latitude in degrees. |
longitude | This is a required. This parameter defines the longitude in degrees. |
Here is an exmaple of date_sun_info() function in PHP:
<html> <body> <?php echo "<h3>Date: 01 Feb, 2020</h3>"; $sun_info=date_sun_info(strtotime("2020-02-01"),21.7679,78.8718); foreach ($sun_info as $key=>$val) { echo "$key: " . date("H:i:s",$val) . "<br>"; } ?> </body> </html>
Example 2
<html> <body> <?php echo "<h3>Date: 1st January, 2020</h3>"; $sun_info=date_sun_info(strtotime("2020-01-01"),31.7667,35.2333); foreach ($sun_info as $key=>$val) { echo "$key: " . date("H:i:s",$val) . "<br>"; } echo "<h3>Date: 10th June, 2020</h3>"; $sun_info=date_sun_info(strtotime("2020-06-10"),31.7667,35.2333); foreach ($sun_info as $key=>$val) { echo "$key: " . date("H:i:s",$val) . "<br>"; } ?> </body> </html>