date_sun_info

(PHP 5 >= 5.1.2, PHP 7)

date_sun_infoReturns an array with information about sunset/sunrise and twilight begin/end

说明

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

参数

time

Timestamp.

latitude

Latitude in degrees.

longitude

Longitude in degrees.

返回值

Returns array on success 或者在失败时返回 FALSE. The structure of the array is detailed in the following list:

sunrise
The time of the sunrise (zenith angle = 90°35').
sunset
The time of the sunset (zenith angle = 90°35').
transit
The time when the sun is at its zenith, i.e. has reached its topmost point.
civil_twilight_begin
The start of the civil dawn (zenith angle = 96°). It ends at sunrise.
civil_twilight_end
The end of the civil dusk (zenith angle = 96°). It starts at sunset.
nautical_twilight_begin
The start of the nautical dawn (zenith angle = 102°). It ends at civil_twilight_begin.
nautical_twilight_end
The end of the nautical dusk (zenith angle = 102°). It starts at civil_twilight_end.
astronomical_twilight_begin
The start of the astronomical dawn (zenith angle = 108°). It ends at nautical_twilight_begin.
astronomical_twilight_end
The end of the astronomical dusk (zenith angle = 108°). It starts at nautical_twilight_end.

The values of the array elements are either UNIX timestamps, FALSE if the sun is below the respective zenith for the whole day, or TRUE if the sun is above the respective zenith for the whole day.

更新日志

版本 说明
5.2.2 The order of latitude and longitude has been swapped.

范例

Example #1 A date_sun_info() example

<?php
$sun_info 
date_sun_info(strtotime("2006-12-12"), 31.766735.2333);
foreach (
$sun_info as $key => $val) {
    echo 
"$key: " date("H:i:s"$val) . "\n";
}
?>

以上例程会输出:

sunrise: 05:52:11
sunset: 15:41:21
transit: 10:46:46
civil_twilight_begin: 05:24:08
civil_twilight_end: 16:09:24
nautical_twilight_begin: 04:52:25
nautical_twilight_end: 16:41:06
astronomical_twilight_begin: 04:21:32
astronomical_twilight_end: 17:12:00

Example #2 Polar night

<?php
var_dump
(date_sun_info(strtotime("2017-12-21"), 900));
?>

以上例程会输出:

array(9) {
  ["sunrise"]=>
  bool(false)
  ["sunset"]=>
  bool(false)
  ["transit"]=>
  int(1513857490)
  ["civil_twilight_begin"]=>
  bool(false)
  ["civil_twilight_end"]=>
  bool(false)
  ["nautical_twilight_begin"]=>
  bool(false)
  ["nautical_twilight_end"]=>
  bool(false)
  ["astronomical_twilight_begin"]=>
  bool(false)
  ["astronomical_twilight_end"]=>
  bool(false)
}

Example #3 Midnight sun

<?php
var_dump
(date_sun_info(strtotime("2017-06-21"), 900));
?>

以上例程会输出:

array(9) {
  ["sunrise"]=>
  bool(true)
  ["sunset"]=>
  bool(true)
  ["transit"]=>
  int(1498046510)
  ["civil_twilight_begin"]=>
  bool(true)
  ["civil_twilight_end"]=>
  bool(true)
  ["nautical_twilight_begin"]=>
  bool(true)
  ["nautical_twilight_end"]=>
  bool(true)
  ["astronomical_twilight_begin"]=>
  bool(true)
  ["astronomical_twilight_end"]=>
  bool(true)
}

参见

相关文章
php date/time 函数 别名 datetime createfromformatphp date/time 函数 get info about given date formatted according to the specified formatphp date/time 函数 returns associative array with detailed info about given datephp date/time 函数 returns an array with information about sunset/sunrise and twilight begin/endphp gnupg 函数 returns an array with information about all keys that matches the given patternphp grapheme 函数 returns part of haystack string from the first occurrence of case insensitive needle to the end of haystackphp mailparse 函数 returns an associative array of info about the messagephp mailparse 函数 returns an array of mime section names in the supplied messagephp mysqlnd memcache 函数 returns information about the plugin configurationphp odbc 函数 returns information about a current connectionphp sqlsrv 函数 returns information about the client and specified connectionphp sqlsrv 函数 returns error and warning information about the last sqlsrv operation performedphp sqlsrv 函数 returns information about the serverphp date/time 函数 returns the timezone name from abbreviationphp date/time 函数 别名 datetimezone gettransitionsphp com 函数 converts a variant date/time value to unix timestampphp wincache 函数 retrieves information about file cache memory usagephp hyperwave api 函数 returns statistics about database serverphp hyperwave api 函数 returns information about server configurationphp mongodb driver server returns an array of information about this server
关注编程学问公众号