Home  >  Article  >  Backend Development  >  date_sun_info() function in PHP

date_sun_info() function in PHP

WBOY
WBOYforward
2023-09-17 15:17:021763browse

date_sun_info() function in PHP

date_sun_info() function returns an array containing information about sunset/sunrise and twilight start/end.

Syntax

date_sun_info(timestamp, latitude, longitude)

Parameters

  • Timestamp - Timestamp. Required.

  • Latitude - Latitude in degrees. Required

  • Longitude - Longitude in degrees. Required

Returns

The date_sun_info() function returns an array containing information about sunset/sunrise and twilight start/end.

The structure of the array is detailed in the following list -

  • sunrise - The time of sunrise (zenith angle = 90°35 ').

  • Sunset - Sunset time (zenith angle = 90°35').

  • Transit - The time when the Sun is at its zenith, that is, when it reaches its highest point.

  • Civil_twilight_begin - The beginning of civil twilight (zenith angle = 96°). It ends at sunrise.

  • civil_twilight_end - The end of civil twilight (zenith angle = 96°). It starts at sunset.

  • nautical_twilight_begin - Beginning of nautical twilight (zenith angle = 102°). It ends with Civil_twilight_begin.

  • nautical_twilight_end - End of nautical twilight (zenith angle = 102°). It starts with Civil_twilight_end.

  • astronomical_twilight_begin - The beginning of astronomical twilight (zenith angle = 108°). It ends with nautical_twilight_begin.

  • astronomical_twilight_end - The end of astronomical twilight (zenith angle = 108°). It starts with nautical_twilight_end.

Example

The following is an example -

Real-time demonstration

<?php
$info = date_sun_info(strtotime("2018-09-23"), 31.7667, 35.2333); foreach ($info as $key => $val) {
   echo "$key: " . date("H:i:s", $val) . "</p><p>";
}
?>

Output

sunrise: 03:28:06
sunset: 15:34:29
transit: 09:31:18
civil_twilight_begin: 03:03:51
civil_twilight_end: 15:58:44
nautical_twilight_begin: 02:35:30
nautical_twilight_end: 16:27:05
astronomical_twilight_begin: 02:06:54
astronomical_twilight_end: 16:55:41

The above is the detailed content of date_sun_info() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete