douchun1961 2011-05-27 12:45
浏览 85
已采纳

函数date_sunrise()返回错误的时间并可能返回结果

There are two things I do not understand about this function:

1.Offset not being taken into account when using in the format SUNFUNCS_RET_TIMESTAMP. For example if I use for the format SUNFUNCS_RET_STRING and use this code:

$lat = 46.055556;    // Latitude (Ljubljana).
$long = 14.508333;    // Longitude (Ljubljana).
$offset = 2;    // Difference between GMT and local time in hours.
$zenith = 90 + 50 / 60;

echo "<br><p>Sunrise: " . date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset);
echo "<br>Sunset: " . date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset);

Then it will display somehow correct answear (by what I mean somehow will explain in second point):

Sunrise: 05:15 Sunset: 20:42

Now if I use SUNFUNCS_RET_TIMESTAMP and convert it to string representation of date with function date():

$lat = 46.055556;    // Latitude (Ljubljana).
$long = 14.508333;    // Longitude (Ljubljana).
$offset = 2;    // Difference between GMT and local time in hours.
$zenith = 90 + 50 / 60;

$dateSunRise = date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset);
$dateSunSet = date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset);

echo "<br><p>Sunrise: " . date("H:i", $dateSunRise);
echo "<br><p>Sunrise: " . date("H:i", $dateSunSet);

I get this result:

Sunrise: 03:15 Sunrise: 18:42

I checked the timestamp and it sure returns wrong, which is why I do not understand, because I have the same offset defined as in previous example where I used SUNFUNCS_RET_STRING.

2.In first point I have written, that it displays somehow correct answear, here is an explaination by what I mean by that. Our official meteorological agency ARSO updates daily on their pages the information about sunrise and sunset. The page can be found on this link (sorry, because it is not in english). Bottom line is, that for our capital city (Ljubljana) it has this information:

Sunrise: 5:18 Sunrise: 20:41

Where I get with date_sunrise and date_sunset function this:

Sunrise: 05:15 Sunset: 20:42

The parameters are the same as in first point (latitude, longitude, offset, zenith). Now the latitude and longitude are certainly correct (checked with GeoHack for Ljubljana). I am starting to think that this diffrence comes from zenith parameter. But I have searched on the internet and it says this:

The best Overall figure for zenith is 90+(50/60) degrees for true sunrise/sunset

I am clueless why it comes to this diffrence, is it possible that this two functions return wrong result?

  • 写回答

1条回答 默认 最新

  • dou47732 2011-05-27 13:52
    关注

    When you use timestamps, they're almost always UNIX timestamps, which means they're given in UTC. When working with them, you'll have to convert them to your own timezone at the end of the calculation. For your purposes, you probably just want the SUNFUNCS_RET_STRING.

    For the second point, zenith plays a large part in calculating the exact minute of sunrise and sunset. The 90+(50/60) is just a ballpark estimate. There are calculators online which can give you better numbers to use for your coordinates, and they will be different for both sunrise and sunset.

    The following code will give you the numbers you're looking for in Ljubljana:

    $lat = 46.055556;    // Latitude (Ljubljana).
    $long = 14.508333;    // Longitude (Ljubljana).
    $offset = 2;    // Difference between GMT and local time in hours.
    
    $rise_zenith = 90+(25/60);
    $set_zenith = 90+(40/60);
    
    echo "<br>Sunrise: " . date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $rise_zenith, $offset);
    echo "<br>Sunset: " . date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $set_zenith, $offset);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?