Skip to content
Advertisement

PHP get UK local time from Server in different time zone

I have a web server which I do not know what the time zone is set to.

it is now 10:49am in the UK, but when I run the following:

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

The server returns the following time.

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

Now I don’t want to just “Add” one hour onto the time because the time still needs to be correct when time moves forward 1hr or back 1 hr.

Is there a way to get the ACTUAL time for LONDON?

FYI – I have also tried the following without any luck:

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

Many thanks in advance.

Advertisement

Answer

Don’t use gmdate(“d-m-Y H:i:s”) here because it returns GMT. Instead use date(“d-m-Y H:i:s”). Try this –

date_default_timezone_set('Europe/London');
$sTime = date("d-m-Y H:i:s");  
print 'The time is: ' . $sTime;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement