PHP and Timezones

by Anthony on May 4, 2006

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.

{code type=php}
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)
echo date(‘r’);
// Fri, 17 Mar 2006 07:38:30 -0500
How easy is that!

Leave a Comment

Previous post:

Next post: