PHP 从不同时区的服务器获取英国本地时间


PHP get UK local time from Server in different time zone

我有一个不知道时区设置的Web服务器。

现在是英国上午 10:49,但是当我运行以下内容时:

$sTime = gmdate("d-m-Y H:i:s");  
print 'The time is: ' . $sTime;

服务器返回以下时间。

The time is: 24-06-2012 09:49:57

现在我不想只是在时间上"添加"一小时,因为当时间向前移动 1 小时或向后移动 1 小时时,时间仍然需要正确。

有没有办法获得伦敦的实际时间?

仅供参考 - 我也尝试了以下方法,但没有任何运气:

date_timezone_set('Europe/London');
$sTime = gmdate("d-m-Y H:i:s");  
print 'The time is: ' . $sTime;

提前非常感谢。

不要在这里使用 gmdate("d-m-Y H:i:s"),因为它返回 GMT。改用 date("d-m-Y H:i:s")。试试这个——

date_default_timezone_set('Europe/London');
$sTime = date("d-m-Y H:i:s");  
print 'The time is: ' . $sTime;