SetEnv TZ vs date.timezone

2019-06-20 14:59发布

问题:

What is the difference between setting the timezone in Apache's SetEnv TZ (.htaccess) and PHP's date.timezone (php.ini)? I haven't been able to detect how SetEnv TZ gets used. I tried setting SetEnv TZ to one value and date.timezone to another timezone but only the latter, date.timezone, seems to have any effect on the web pages. I'm also wondering how Apache configuratoins and PHP configurations, for the same things, affect the server, such as which overwrites which.

回答1:

The URL http://www.php.net/manual/en/function.date-default-timezone-get.php should give you the exact answer; in short (assuming a recent version of php > 5.4.0) it checks for the one set with date_default_timezone_set() within php and if not set, checks the value of date.timezone in php.ini. If that one is unset - it gives up. So TZ is ignored.

Or in other words for > 5.4.0 the environment variable TZ is never consulted.

For 5.4.0 and before - it is consulted when no default/ini is set. See the above URL for exact order and details.