Reputation: 2843
I have the following code:
var_dump(new \DateTime('now', new DateTimeZone('GMT')));
which i get the following output, which is one hour behind:
object(DateTime)#894 (3) { ["date"]=> string(19) "2012-09-13 13:54:26" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "UTC" }
However if i change the code to the following:
var_dump(new \DateTime('now', new DateTimeZone(date_default_timezone_get())));
I then get the folling output which is right:
object(DateTime)#894 (3) { ["date"]=> string(19) "2012-09-13 14:54:26" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London" }
I was reading on Derick Rethans blog that with timezone 3 it should take into account, any daylight saving hours, can anyone explain why on the first code snippet I get one hour before what it actually is?!
Upvotes: 0
Views: 1962
Reputation: 1500335
Well, in the first snippet you're asking for a time zone of "GMT". That's a somewhat ambiguous term, but I'd normally expect that to mean exactly GMT itself - roughly equivalent to UTC, and without any daylight saving time. That's why it's not applying daylight saving time, and it's reporting the time zone as UTC.
The Europe/London time zone spends half the year in GMT, and half the year in BST.
I would suggest that you steer clear of 3-letter time zone abbreviations wherever possible. They're full of all kinds of possibilities for failure. (Having now read the blog post, that's basically what's being suggested there too.)
Upvotes: 2