How to convert timezone in PHP

I noticed that many people tried to find how to convert timezone in PHP in this site but found none. I wrote this trick to help them simplify the problem using very basic feature of PHP. Generally, your server might be set in such a timezone, e.g. GMT+7, and your users may locate in another timzone, e.g. GMT-7. What you need is to allow users to customize view of date/time in webboard, portal, blog, or any interactive websites. This is very basic but impression idea to help user reading and understanding your content easier.

If you notice the characteristic of each timezone, there is a reference point or so called GMT or UTC. They are the same point. That means every timezones are relative to this reference point. Each point is represented by offset of hours and minutes in form "SHHMM" while S denotes the sign of this offset, HH denotes the offset in hour and MM denotes the offset in minutes. For example, Bangkok timezone is GMT+7 which represents by +0700. Don’t worry everybody know where they are. You can leave the task to choose appropriate timezone to the end-user. My trick is to convert offset string into second so that standard function time() can recognize that offset correctly.

\n"; print "GMT: ".date("D M j G:i:s T Y",$gmt)."
\n"; print "Remote Time (GMT-7): ".date("D M j G:i:s T Y",$remote)."
\n"; ?>

Technorati Tags: , , , , , , , , , ,

It's difficult to read these

It's difficult to read these articles.Pls change the color scheme

Daylight Saving

Hi and thanks for that, but what about daylight saving? The clients offset will change twice a year due to daylight saving!

Post new comment