Click to See Complete Forum and Search --> : Timezones between PHP4 & PHP5


tbirnseth
08-29-2007, 04:24 PM
My test system is PHP4 and my production system is PHP5.

Under PHP4, I previously did:

if( $worker['timezone'] )
putenv("TZ=$worker[timezone]");


Where $worker['timezone'] == "US/Pacific" for example. All works fine. New dates are in the user's timezone as well as system generated dates.

However, under PHP5, it seems that the values for TZ have changed and "US/Pacific" is now "America/Los_Angeles". All okay, I create a map from the PHP4 name to the PHP5 name. I then adjusted the script to:

if( $worker['timezone'] ) {
putenv("TZ=$worker[timezone]"); // PHP4
$tzMap = array('US/Pacific' => 'America/Los_Angeles');
if( function_exists('date_default_timezone_set') ) {
putenv("TZ=".$tzMap[$worker['timezone']]); // PHP5
date_default_timezone_set($tzMap[$worker['timezone']]);
}
}


However, the date() family of functions continue to return dates formatted in the server's timezone rather than what I set above. This is set during initialization of every page invocation.

Can anyone tell me what I'm doing incorrectly? Also, this is running on an Apache/Linux server.

thanks,
tony

NogDog
08-29-2007, 07:48 PM
If using PHP >= 5.1.0, you might want to use date_default_timezone_set (http://www.php.net/date_default_timezone_set)().

tbirnseth
08-29-2007, 08:18 PM
Uh... That's what I'm doing....
I think Ifound the solution...
The date_default_timezone_set() seems to need to be done before the putenv(). Seems to be working but not done testing....

NogDog
08-29-2007, 08:29 PM
Sorry, I just saw the couple of putenv()'s, but the date_default_timezone_set() didn't register on my brain.