date_sun_info

(PHP 5 >= 5.1.2, PHP 7)

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

설명

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

인수

time

Timestamp.

latitude

Latitude in degrees.

longitude

Longitude in degrees.

반환값

Returns array on success실패 시 FALSE를 반환합니다.

예제

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

참고

  • date_sunrise() - Returns time of sunrise for a given day and location
  • date_sunset() - Returns time of sunset for a given day and location

add a note add a note

User Contributed Notes 1 note

up
8
TheFax
2 years ago
In the last example, conversion from seconds to Hour, Minutes, Seconds is wrong.
This is the correct verion:

<?php
$si
= date_sun_info(strtotime('2022-08-26'), 50.45, 30.52);
$diff = $si['sunset'] - $si['sunrise'];  # $diff is measured in seconds.
echo "Length of day: ",
   
floor($diff / 3600), "h",
   
floor(($diff % 3600) / 60), "m",
   
floor($diff % 60), "s\n";
?>

Output:
  Length of day: 13h53m15s
To Top