PHP - Function date_sun_info()


Advertisements


Syntax

array date_sun_info ( int $time, float $latitude, float $longitude );

Definition and Usage

This function returns an array with information about sunset/sunrise and twilight begin/end.

Parameters

Sr.No Parameter & Description
1

time(Required)

Timestamp.

2

latitude(Required)

Latitude in degrees.

3

longitude(Required)

Longitude in degrees.

Return Value

It returns array on success or FALSE on failure.

Example

Following is the usage of this function −

Live Demo
<?php
   $sun_info = date_sun_info(strtotime("2017-07-12"), 31.7667, 35.2333);
   
   foreach ($sun_info as $key => $val) {
      echo "$key: " . date("H:i:s", $val) . "\n";
   }
?> 

This will produce the following result −

sunrise: 02:42:53 sunset: 16:46:42 transit: 09:44:48 civil_twilight_begin: 02:15:18 civil_twilight_end: 17:14:17 nautical_twilight_begin: 01:41:42 nautical_twilight_end: 17:47:53 astronomical_twilight_begin: 01:05:42 astronomical_twilight_end: 18:23:53

php_function_reference.htm

Advertisements