date_sun_info() - php 日期时间函数
date_sun_info()
(PHP 5 >= 5.1.2, PHP 7)
Returns an array with information about sunset/sunrise and twilight begin/end
说明
date_sun_info(int $time,float $latitude,float $longitude): array参数
$timeTimestamp.
$latitudeLatitude in degrees.
$longitudeLongitude in degrees.
返回值
Returns array on success 或者在失败时返回FALSE
. The structure of the array is detailed in the following list:
The values of the array elements are either UNIX timestamps,FALSE
if the sun is below the respective zenith for the whole day,orTRUE
if the sun is above the respective zenith for the whole day.
更新日志
版本 | 说明 |
---|---|
5.2.2 | The order of$latitudeand$longitudehas been swapped. |
范例
Adate_sun_info()example
以上例程会输出:
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
Polar night
以上例程会输出:
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) }
Midnight sun
以上例程会输出:
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) }
参见
date_sunrise()
返回给定的日期与地点的日出时间date_sunset()
返回给定的日期与地点的日落时间
I have been working on my own php script to get current down or up for sun and moon. I had to add function for any places that have 24 hour sun. here is my code for places with 24 hour sun.
maybe I am wrong, but I think SUNFUNCS_RET_TIMESTAMP return GMT(0) time SUNFUNCS_RET_STRING Return local time SUNFUNCS_RET_DOUBLE Return local time
We needed the length of the day, both sunrise to sunset and twilight to twilight for particular latitudes. Sun_info() is just the thing. We mistakenly thought 'transit' was this value, which it is not. Transit is the time of day the sun is at its zenith. To get length of day, one must perform math on the results of sun_info(). When doing math with time values, don't expect date() to do the conversion to hours:minutes:seconds. date() thinks the passed value is a time since the epoch. You will need to do your own conversion to hours:minutes:seconds, using something like the following: Regarding date_sunrise() and date_sunset(), these both return values without seconds and without correction for Daylight time. Whereas sun_info() handles seconds as well as Daylight time. It even handles dates prior to the epoch correctly as negative timestamps, at least as of php 5.2.12 For example, sun_info(strtotime('July 4, 1776'),47.3506,-122.6417) produces something like the following when using date_default_timezone_set('America/Los_Angeles') and date("H:i:s", $val) sunrise: 04:20:26 [-6106016374] sunset: 20:09:03 [-6105959457] transit: 12:14:45 [-6105987915] civil_twilight_begin: 03:40:54 [-6106018746] civil_twilight_end: 20:48:35 [-6105957085] nautical_twilight_begin: 02:46:58 [-6106021982] nautical_twilight_end: 21:42:31 [-6105953849] astronomical_twilight_begin: 01:28:06 [-6106026714] astronomical_twilight_end: 23:01:23 [-6105949117] * * *
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)