3

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
Gravy
  • 12,264
  • 26
  • 124
  • 193
  • You should enable error reporting so you understand what's not working with your code, e.g. the way you used the `date_timezone_set` function. – hakre Jun 24 '12 at 15:31
  • possible duplicate of [Convert timezone in php](http://stackoverflow.com/questions/9835256/convert-timezone-in-php) – hakre Jun 24 '12 at 15:34
  • Or the many others like [How can I get the user's local time instead of the server's time?](http://stackoverflow.com/questions/2705067/how-can-i-get-the-users-local-time-instead-of-the-servers-time) – hakre Jun 24 '12 at 15:36
  • Or even with your exact timezone: [Timezone conversion in php](http://stackoverflow.com/questions/2505681/timezone-conversion-in-php) – hakre Jun 24 '12 at 15:45
  • WOW somebody woke up on the wrong side of the bed!!! Don't you think I tried reading up on this already? If you read my comment on solution below, you will CLEARLY see that I thought GMT time and LONDON time was the same thing. Simply confusing the two meant that my code was wrong. Don't think that this deserved rating question down, don't think that this needed 4 completely unhelpful comments insinuating that I haven't done any research. Don't think this required you being that pernickety and editing my question just to remove the tag PHP5. relax a bit on trying to up your comment count. – Gravy Jun 24 '12 at 22:05
  • @Gracy: I was in full good faith, that you did everything yourself possible to solve the issue on your own, I just left some commentary and rated the quality of your question. And actually it was not clear to me that you mixed wordings here, otherwise naturally this would have been obviously too localized and/or not a real question firsthand. – hakre Jun 24 '12 at 23:22

1 Answers1

17

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;
smm
  • 527
  • 5
  • 17
  • 3
    Only for part of the year: in the summer it's BST (British Summer Time), one hour ahead of GMT. – deltab May 04 '13 at 16:54