/    Sign up×
Community /Pin to ProfileBookmark

Timezones between PHP4 & PHP5

My test system is PHP4 and my production system is PHP5.

Under PHP4, I previously did:

[CODE]
if( $worker[‘timezone’] )
putenv(“TZ=$worker[timezone]”);
[/CODE]

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:

[CODE]
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’]]);
}
}
[/CODE]

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 30.2007 — If using PHP >= 5.1.0, you might want to use [url=http://www.php.net/date_default_timezone_set]date_default_timezone_set[/url]().
Copy linkTweet thisAlerts:
@tbirnsethauthorAug 30.2007 — 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....
Copy linkTweet thisAlerts:
@NogDogAug 30.2007 — Sorry, I just saw the couple of putenv()'s, but the date_default_timezone_set() didn't register on my brain.
×

Success!

Help @tbirnseth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...