PHP date.timezone warning fix

OK, Have you gotten this (or similar):
PHP Warning: PHP Startup: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for '-8.0/no DST' instead in Unknown on line 0

I am running PHP 5.3.0 on my Windows XP, and have spent the better part of the day to try to get rid of this warning and finally managed to do it. How, you say?

The breakthrough came after I have read this instructions from the PHP web site Changes in PHP datetime support. Here is part of it:

Since PHP 5.1.0, there has been an extension named date in the PHP core. This is the new implementation of PHP’s datetime support. Although it will attempt to guess your system’s timezone setting, you should set the timezone manually. You can do this in any of three ways:

  • in your php.ini using the date.timezone INI directive
  • ion your system using the TZ environmental variable
  • ifrom your script using the convenience function date_default_timezone_set()

All supported timezones are listed in the PHP Manual.

Notice that you can set your system’s timezone setting using php.ini, set TZ environment variable or from your php script.

The first option did not work for me. The third option does not work for php scripts that are not written by me, so the only option left is to set environment variable TZ. That finally saved the day!
On Windows XP:

  1. go to My Computer
  2. View System Information
  3. Advanced Tab
  4. Environmental Variables
  5. Add New Variable with name ‘TZ’ and value whatever your timezone is. In my case is ‘America/Los_Angeles’.

That’s it. I hope this saves somebody few hours of searching.

Comments

Popular posts from this blog

Enable pgpass under Windows 7

Numeric Drop-down With PHP ranges

PHPUnit 4 on Windows 7