English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial básico do PHP

Tutorial avançado do PHP

PHP & MySQL

Manual de referência do PHP

Uso e exemplo da função PHP date_sun_info()

Manual do PHP Date & Time

A função date_sun_info() retorna um array contendo informações sobre o nascer do sol/Pôr do sol e início do crepúsculo/Informações sobre o fim do crepúsculo no array.

Definição e uso

A função date_sun_info() aceita o tempo, latitude e longitude da posição e fornece informações sobre o nascer do sol/Início do pôr do sol e do crepúsculo/结束的信息。

Sintaxe

date_sun_info($timestamp, $latitude, $longitude)

Parâmetro

Número de ordemParâmetros e descrição
1

timestamp (obrigatório)

Isso especifica um timestamp.

2

latitude (obrigatório)

Isso especifica a latitude da posição.

3

longitudade (obrigatório)

this specifies the longitude of the location.

return_value

date_sun_info() function returns an array containing information about sunrise/sunset and dusk start/结束的信息。

PHP版本

此函数最初是在PHP版本5.2中引入的,并且可以在所有更高版本中使用。

online_example

以下示例演示了date_sun_info()函数用法-

<?php
   $sun_info = date_sun_info("02-17-2012", 20.5937, 78.9629);
   print_r($sun_info);
?>
test_see‹/›

output_result

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
)

online_example

以下示例获取同一日期在不同位置的信息-

<?php
   $sun_info = date_sun_info("02-17-2012", 37.0902, 95.7129);
   print_r($sun_info);
?>
test_see‹/›

output_result

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
)

online_example

以下示例在不同日期获取位置信息-

<?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));
?>
test_see‹/›

output_result

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
)

online_example

<?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";
   }
?>
test_see‹/›

output_result

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