PHP date_sun_info erroneously

I am trying to use the PHP function date_sun_infoto get the time information of certain sun positions during the day:

I am currently using code similar to the code in the documentation .

$sun_info = date_sun_info(strtotime('today'), 40.42, 74.0);
foreach ($sun_info as $key => $val) {
    echo "$key: " . date("H:i:s", $val) . "<br>";
}

Output:

sunrise: 20:50:20
sunset: 07:45:03
transit: 02:17:41
civil_twilight_begin: 20:22:45
civil_twilight_end: 08:12:38
nautical_twilight_begin: 19:51:01
nautical_twilight_end: 08:44:22
astronomical_twilight_begin: 19:19:28
astronomical_twilight_end: 09:15:55

Which is clearly wrong.

I am not sure why this is happening. Any help would be greatly appreciated.

I thought it was related to time zones? If so, how can I fix this? The time zone for the server is set to America / New_York, which will be 5 hours behind GMT, but even so, the times may be wrong if I don't count on it wrong.

+3
source share
3 answers

, . 40.42, 74.0 . , 40.42, -74 () -?

, , , , :

  • - GMT + 6
  • - - GMT-5

11 .

- 7:50 , 20:50 - .

+4

@Pekka, , , .

, , date_sunrise/date_sunset. , , , , ($ timezone - tz , lat/long points):

    // push tz
    $tz = date_default_timezone_get();
    date_default_timezone_set($timezone);
    $dsi = date_sun_info($timestamp, $latitude, $longitude);
    // pop tz
    date_default_timezone_set($tz);

UTC, $ , () :

    $dsi_tz = new DateTimeZone($timezone);
    $sunrise = new DateTime("@" . $dsi['civil_twilight_begin']);
    $sunrise->setTimezone($dsi_tz);
    echo $sunrise->format('Y-m-d H:i:s e');
    $sunset = new DateTime("@" . $dsi['civil_twilight_end']);
    $sunset->setTimezone($dsi_tz);
    echo $sunset->format('Y-m-d H:i:s e');

: , UTC, , . , , - .

+1

, , @Pekka , ( ), , .

, script, , lat/long , / . , php.ini. [Date] ini ( ), .

( ), , , , , "UTC" , "/", ( ).

0

Source: https://habr.com/ru/post/1793384/


All Articles