PHP date_sun_info 错误时间 [英] PHP date_sun_info wrong times

查看:28
本文介绍了PHP date_sun_info 错误时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP 的 date_sun_info 函数来获取有关一天中某些太阳位置的时间的信息:

I'm trying to use PHP's date_sun_info function to get information about the time of certain positions of the sun throughout the day:

目前我使用的代码类似于文档中的代码.

At the moment I'm using code similar to that 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>";
}

输出为:

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

这显然是错误的.

我不确定为什么会发生这种情况.任何帮助将不胜感激.

I'm unsure why this happens. Any help would be much appreciated.

我以为这与时区有关?如果是这样,我应该如何纠正?服务器的时区设置为 America/New_York,这将比 GMT 晚 5 小时,但即使考虑到时间也不对,除非我计算错了.

I had thought that it is something to do with timezones? If so how should I correct for this? The timezone for the server is set to America/New_York which would be 5 hours behind GMT but even taking that into account the times cannot be right, unless I'm calculating this wrong.

推荐答案

我认为您混淆了数字.40.42, 74.0 翻译成吉尔吉斯斯坦山区的一个点.您的意思可能是 40.42, -74 对于(大约)纽约?

I think you mixed up the numbers. 40.42, 74.0 translates to a point in the mountains of Kyrgysztan. You probably meant 40.42, -74 for (approximately) New York?

至于为什么会发生这种情况,该函数似乎确实对时区敏感,但没有正确记录:

As to why this happens, it seems like the function is indeed time zone sensitive, something that is not properly documented:

  • 吉尔吉斯斯坦是 GMT+6
  • 纽约是 GMT-5

这相当于相差 11 小时.

that amounts to a difference of 11 hours.

那时的日出时间是当地时间 7:50,纽约时间 20:50.

Sunrise time at that point is 7:50 local time, 20:50 New York time.

这篇关于PHP date_sun_info 错误时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆