Time zones and PHP question ...
July 27, 2009 7:05 AM Subscribe
PHP gurus: please help me do something specific with the date function.
So my website uses some logic to determine what time of day/day of week it is, and display content accordingly. It all hinges on this variable:
$now = date('l H:i');
Over the weekend, we moved web hosts - to a company in California, and now the dynamic content is always three hours off. I've looked up the documentation on the function, and it makes my head hurt. What do I do to that variable assignment to add three hours to the result it returns?
So my website uses some logic to determine what time of day/day of week it is, and display content accordingly. It all hinges on this variable:
$now = date('l H:i');
Over the weekend, we moved web hosts - to a company in California, and now the dynamic content is always three hours off. I've looked up the documentation on the function, and it makes my head hurt. What do I do to that variable assignment to add three hours to the result it returns?
Response by poster: Awesome ... thanks! That saves the day.
posted by jbickers at 7:36 AM on July 27, 2009
posted by jbickers at 7:36 AM on July 27, 2009
You can either change the defeault timezone:
date_default_timezone_set('UTC');
or specify the timezone when you call date, something like:
$now = date('l H:i UTC');
posted by devnull at 7:39 AM on July 27, 2009
date_default_timezone_set('UTC');
or specify the timezone when you call date, something like:
$now = date('l H:i UTC');
posted by devnull at 7:39 AM on July 27, 2009
You can also use a datetime object
$EastCoast = new DateTimeZone("America/New_York");
$now = new DateTime("now",$EastCoast);
$now->format("l H:i");
posted by Nothing at 8:41 AM on July 27, 2009
$EastCoast = new DateTimeZone("America/New_York");
$now = new DateTime("now",$EastCoast);
$now->format("l H:i");
posted by Nothing at 8:41 AM on July 27, 2009
It would be much simpler -- and you wouldn't have to modify any of your code -- if you could just request your web host to change the server time to Eastern instead of Pacific.
Several of my largest clients are in New York, but most of my servers are in Portland. The servers are just set to Eastern time.
posted by GatorDavid at 10:05 AM on July 28, 2009
Several of my largest clients are in New York, but most of my servers are in Portland. The servers are just set to Eastern time.
posted by GatorDavid at 10:05 AM on July 28, 2009
This thread is closed to new comments.
This is not the most correct way to do it, and if you switch timezones again, you'll have to change the code again. What you should really do is use this function to change your timezone to "America/New_York".
posted by mkb at 7:19 AM on July 27, 2009