Re: How to show proper time to users from around the world

From: Date: Wed, 29 Aug 2007 07:34:23 +0000
Subject: Re: How to show proper time to users from around the world
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-261440@lists.php.net to get a copy of this message
On 8/29/07, Hemanth <mvhemanth@gmail.com> wrote: > Hi friends, > > Is there a solution to showing the proper time and date at user > browsers > and also recording proper USER times in the database operations in > mysql if you have the opportunity to have them input the time, you can then use putenv("TZ=America/Los_Angeles") before any time operations and they will be localized. it will accept any of the timezone library definitions (or what you select for instance on unix libraries) there's also a new date extension available as of one of the latest php versions i believe that makes it even easier. http://us3.php.net/manual/en/ref.datetime.php has the info. for mysql data exchange you can use FROM_UNIXTIME and UNIX_TIMESTAMP(NOW()) for example; if you dig it out from the database and use the PHP functions it will localize it properly still. i don't even fuss with this stuff anymore, i have a date formatting function which takes $visitor['timezone'] (which is pre-populated with a default, and overridden if the user has defined a different one) and uses putenv("TZ=$foo") before i do the actual date/function calls - it's been working flawlessly for years. i could probably update it now to use the new extension too, natively maybe it would work slightly faster than environment setting. trying to detect the timezone offset from the browser i do not think can be done consistently. i don't think i've seen anything that is considered foolproof for that. maybe just DST checks...

« previous php.general (#261440) next »