Setting default timezone


#1

How can I set the default timezone for php? I don’t want to set it using date_default_timezone_set(). I tried following the wiki but it didn’t work. http://wiki.dreamhost.com/Running_web_scripts_in_your_Timezone

Is the wiki out of date? Last time I tried to follow something in the wiki the problem was that I was on an apache 2 server and the relevant mod wasn’t installed. Could this be the problem again?

Present error I’m getting is “It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function.”

As I don’t want to use date_default_timezone_set(), so is it possible to set the default timezone in one of the other manners?


#2

You could use putenv() in the script itself. If you search through that page for “TZ=” you’ll see info about setting the timezone.


:stuck_out_tongue: Save up to $96 at Dreamhost with ALMOST97 promo code (I get $1).
Or save $97 with THEFULL97.


#3

Hi thanks for that seiler. Yes putenv would work but the reason I didn’t want date_default_timezone_set() is I’m trying to avoid a script based solution. i.e. htaccess solution or other similar please?

Maybe I’ll have to go with a custom php installation but that seems pretty extreme :stuck_out_tongue:


#4

I’m not sure why SetEnv TZ in the .htaccess wouldn’t work, unless it has something to do with PHP/CGI, or certain versions of PHP.


:stuck_out_tongue: Save up to $96 at Dreamhost with ALMOST97 promo code (I get $1).
Or save $97 with THEFULL97.


#5

Does it work on yours? If so maybe it’ll help us confirm that it’s because we have different php/apache versions.

All you need is a htaccess with a timezone set and a php file as below…

error_reporting(E_ALL | E_STRICT);
$foo = time();

…which will generate a notice if a default timezone isn’t selected.


#6

The only way I was able to change the timezone was within the script, so I’m not sure what the deal is with .htaccess.


:stuck_out_tongue: Save up to $96 at Dreamhost with ALMOST97 promo code (I get $1).
Or save $97 with THEFULL97.


#7

Thanks for trying :slight_smile: I appreciate your time.

I’ll look at it again after I sleep. I think it’s an apache config issue e.g. mod not installed.


#8

Can anyone say if work with .htaccess?


#9

Not sure if following is pertinent to subject.
I have added ‘SetEnv TZ Australia/Melbourne’ to my .htaccess file and my cgi script running the pagehit counters now use local time rather than server time.
Regards, tomt