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

date_sun_info() function in PHP

WBOY
Release: 2023-09-17 15:18:01
forward
1788 people have browsed it

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)
Copy after login

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>";
}
?>
Copy after login

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
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template