setting default timezone

setting default timezone

Posted by: ecvej
Posted on: 2007-08-03 12:09:00

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?

Re: setting default timezone

Posted by: seiler
Posted on: 2007-08-03 13:04:00

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

Re: setting default timezone

Posted by: ecvej
Posted on: 2007-08-03 13:23:00

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 :P

Re: setting default timezone

Posted by: seiler
Posted on: 2007-08-03 13:34:00

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.

Re: setting default timezone

Posted by: ecvej
Posted on: 2007-08-03 14:01:00

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.

Re: setting default timezone

Posted by: seiler
Posted on: 2007-08-03 19:56:00

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.


Re: setting default timezone

Posted by: ecvej
Posted on: 2007-08-03 20:15:00

Thanks for trying :-) 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.

Re: setting default timezone

Posted by: Nirloz
Posted on: 2007-12-12 16:02:00

Can anyone say if work with .htaccess?

Re: setting default timezone

Posted by: tomt
Posted on: 2007-12-13 02:20:00

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

Tags: default timezonedreamhostwikiweb scriptsapache 2environment variablelast time