fergusweb network

PHP and Timezones

May 4th, 2006 Anthony

Its always a hassle, isn’t it. You code up your webapp and store timestamps from events - then later you have to do the conversion in your head because the server your site sits on is on the other side of the world.

Michael Phipps touches on the subject, mentioning an issue with attempting local timezones in multi-user systems.

Last week Pete was trying to solve a problem, and ran into the issue of not being able to change the timezone on his server, even though he needed all times stored in Australian Eastern Standard. As one does, he didn’t find a decent solution until he’d already implemented a hack.

echo date('r');
// Fri, 17 Mar 2006 12:38:30 +0000
?>

If you do not have access to editing the server time, here's a quick fix:

// For example, to output Eastern Standard Time (GMT -5:00)
putenv("TZ=EST");
echo date('r');
// Fri, 17 Mar 2006 07:38:30 -0500
?>

How easy is that!

Posted in General, Web Dev

Please Note: Comment moderation is enabled - your comment will not appear until approved.





XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>