我的 PHP 代码中的 strtotime 有这个问题,有时它是错误的(仅适用于某些时区),而对其他人来说是正确的!
我无法理解它。
我也在<?php date_default_timezone_set('GMT'); ?>
页面顶部设置了,但这没有帮助!
基本上它的作用是根据 if 和 else if 条件将offset/3600
值添加或减去设置时间。$time1 = strtotime('00:00');
offset/3660 值是两个时区之间的时间差!
下面的代码适用于某些位置,但不适用于其他位置!基本上它会增加额外的 1-2 小时或起飞/减去额外的 1-2 小时(不是所有时间)。
即阿比让和伦敦之间的时差是-1。应显示的时间(值)为 23:00,即 00:00 - 01:00 = 23:00。但显示的值为 00:00。
但是,正如我提到的,它适用于某些时区。即纽约和伦敦之间的时差是-5,代码有效,它显示 19:00 为 00:00 - 05:00 = 19:00
有人可以解释一下吗?
这是有问题的代码:
<?php
$time1 = strtotime('00:00');
if (0 > $offset)
{
// For negative offset (hours behind)
$hour_dif = date('H:i', strtotime($time1 -$offset/3600));
$time1 = "{$hour_dif}";
}
elseif (0 < $offset)
{
// For positive offset (hours ahead)
$hour_dif = date('H:i', strtotime($time1 +$offset/3600));
$time1 = "{$hour_dif}";
}
else
{
// For offsets in the same timezone.
$time1 = "in the same timezone";
}
echo "{$time1}";
?>