注意:这是我的好奇心练习,已有解决此问题的功能/代码(另请参见注释)
可以在此处找到用于计算日出和日落时间的算法,以及在1 in Tcl
和2 in的实现javascript
。
我正在尝试将算法转换为PHP,但是这有点麻烦,并且花费太多时间。到目前为止,这是我的结果:
<?php
$sunrise = sunriseSunsetTimeTest(9, 4, 2015, 46.929512, 7.565272);
$sunset = sunriseSunsetTimeTest(9, 4, 20, 46.929512, 7.565272, 'sunset');
echo $sunrise . '/' . $sunset;
/* output is: 12.314714533758/12.612340511889 (?) */
function sunriseSunsetTimeTest($day, $month, $year, $latitude, $longitude,
$which='sunrise', $localTimeOffset=1, $zenith=96){
/*
* Output:
* sunrise or sunset time depending on parameter $which
*
* Input:
* (int) day
* (int) month
* (int) year
* (float) latitude_degree
* (float) longitude_degree …
Run Code Online (Sandbox Code Playgroud) 我有一个网络摄像头网站,我想显示实际一天的日出时间。因此我使用 PHP 中的 date_sunrise 函数来实现此目的。除了坐标之外,它还接受太阳天顶值作为输入。
我了解到日出的正确天顶是 90.8333。90 度是与太阳中心(即地平线)的理论角度。为了考虑太阳的直径和折射,添加了 0.8333(16 角分 + 34 角分除以 60)。
但我注意到这个输入给出的日出时间与其他网站不同。最可靠的来源一定是美国海军天文台天文应用部。查看他们的在线计算器并阅读他们的方法的描述。据说他们还使用天顶值 90.8333 来计算日出。
然后我发现php函数date_sun_info是一个包含各种数据的数组,给出了正确的日出时间(对应于AAD的结果)。
为了从 date_sunrise 函数获得相同的日出时间,我必须输入 90.5 左右的天顶值。
为什么 zenith=90.8333 的 date_sunrise 不会给出与 date_sun_info 相同的结果?