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
  • on your system using the TZ environmental variable
  • from 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.php

2 Comments to “PHP date.timezone warning fix”

  1. Simon Plangger 4 February 2010 at 3:55 am #

    Thanks a lot for your Information. I’m using Zend Community Server on Windows XP and working with the Zend Framework CLI tool has always triggert this message.

    The environmental variable solved the problem.

    Thanks, again

  2. Steven 9 March 2010 at 9:23 am #

    Thanks so much for this! I’ve been trying to find a solution to this for ages, and setting the environment variable worked.

    Now if anyone else has the time, it would be interesting to know why the php.ini date.timezone setting is not sufficient?


Leave a Reply

Spam Protection by WP-SpamFree