date_sun_info()函數(shù)返回一個包含有關(guān)指定日期與地點的日出/日落和黃昏開始/黃昏結(jié)束的信息的數(shù)組。
date_sun_info()函數(shù)接受位置的時間,緯度和經(jīng)度,并在給定位置提供有關(guān)日出/日落以及黃昏開始/結(jié)束的信息。
date_sun_info($timestamp, $latitude, $longitude)
序號 | 參數(shù)及說明 |
---|---|
1 | timestamp (必需) 這指定一個時間戳。 |
2 | latitude (必需) 這指定位置的緯度。 |
3 | longitude (必需) 這指定位置的經(jīng)度。 |
date_sun_info()函數(shù)返回一個數(shù)組,該數(shù)組包含有關(guān)指定位置中給定日期的日出/日落以及黃昏的開始/結(jié)束的信息。
此函數(shù)最初是在PHP版本5.2.0中引入的,并且可以在所有更高版本中使用。
以下示例演示了date_sun_info()函數(shù)的用法-
<?php $sun_info = date_sun_info("02-17-2012", 20.5937, 78.9629); print_r($sun_info); ?>測試看看?/?
輸出結(jié)果
Array ( [sunrise] => 4818 [sunset] => 44087 [transit] => 24453 [civil_twilight_begin] => 3381 [civil_twilight_end] => 45524 [nautical_twilight_begin] => 1729 [nautical_twilight_end] => 47176 [astronomical_twilight_begin] => 98 [astronomical_twilight_end] => 48807 )
以下示例獲取同一日期在不同位置的信息-
<?php $sun_info = date_sun_info("02-17-2012", 37.0902, 95.7129); print_r($sun_info); ?>測試看看?/?
輸出結(jié)果
Array ( [sunrise] => 3038 [sunset] => 37825 [transit] => 20431 [civil_twilight_begin] => 1307 [civil_twilight_end] => 39556 [nautical_twilight_begin] => -642 [nautical_twilight_end] => 41505 [astronomical_twilight_begin] => -2538 [astronomical_twilight_end] => 43402 )
以下示例在不同日期獲取位置信息-
<?php $time = "2000-01-01"; $latitude = 31.7667; $longitude = 35.2333; print_r(date_sun_info($time, $latitude, $longitude)); $time = "2010-01-01"; print_r(date_sun_info($time, $latitude, $longitude)); $time = "2020-01-01"; print_r(date_sun_info($time, $latitude, $longitude)); ?>測試看看?/?
輸出結(jié)果
Array ( [sunrise] => 16742 [sunset] => 53161 [transit] => 34951 [civil_twilight_begin] => 15138 [civil_twilight_end] => 54765 [nautical_twilight_begin] => 13316 [nautical_twilight_end] => 56587 [astronomical_twilight_begin] => 11534 [astronomical_twilight_end] => 58369 ) Array ( [sunrise] => 16742 [sunset] => 53161 [transit] => 34951 [civil_twilight_begin] => 15138 [civil_twilight_end] => 54765 [nautical_twilight_begin] => 13316 [nautical_twilight_end] => 56587 [astronomical_twilight_begin] => 11534 [astronomical_twilight_end] => 58369 ) Array ( [sunrise] => 16742 [sunset] => 53161 [transit] => 34951 [civil_twilight_begin] => 15138 [civil_twilight_end] => 54765 [nautical_twilight_begin] => 13316 [nautical_twilight_end] => 56587 [astronomical_twilight_begin] => 11534 [astronomical_twilight_end] => 58369 )
<?php $sun_info = date_sun_info(strtotime("2017-07-12"), 20.5937, 78.9629); foreach ($sun_info as $key => $val) { echo "$key: " . date("H:i:s", $val) . "\n"; } ?>測試看看?/?
輸出結(jié)果
sunrise: 00:11:03 sunset: 13:28:33 transit: 06:49:48 civil_twilight_begin: 23:46:45 civil_twilight_end: 13:52:51 nautical_twilight_begin: 23:17:48 nautical_twilight_end: 14:21:47 astronomical_twilight_begin: 22:47:55 astronomical_twilight_end: 14:51:41