douchun1961 2011-05-27 04: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 05: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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
  • ¥15 距离软磁铁一定距离的磁感应强度大小怎么求
  • ¥15 霍尔传感器hmc5883l的xyz轴输出和该点的磁感应强度大小的关系是什么
  • ¥15 vscode开发micropython,import模块出现异常
  • ¥20 Excel数据自动录入表单并提交
  • ¥30 silcavo仿真,30分钟,只需要代码
  • ¥15 FastReport 怎么实现打印后马上关闭打印预览窗口
  • ¥15 利用3支股票数据估计其均值和方差的95%置信区间。
  • ¥15 微信小程序运行一项功能时,弹出未知错误弹框,检查代码没有问题
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部