Skip to main content

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

Last year I have written a post about enabling pgpass under Windows XP . Today I repeated the procedure for Windows 7. Basically everything worked as before, with the following exception - the APPDATA directory in Win 7 is different. What I did first was to check the name of the user running PostgreSQL server process. Then log in as that user and find out where is the APPDATA directory for that user. echo %APPDATA% From that point on, just follow the instructions in the previous post. Good luck!

Numeric Drop-down With PHP ranges

Here is an easy way to generate form numeric drop-down with ranges. $form = new Zend_Form(); $ranges = array( range(1, 20, 1) , range(30, 100, 10) , range(200, 1000, 100) ); $a = array(); foreach ( $ranges as $range ) { foreach ( $range as $r ) { $a[$r] = $r; } } $form->addElement('select', 'quantity', array( 'label' => 'Quantity' , 'required' => false , 'class' => 'form-control' , 'multiOptions' => array( '' => '--Select--' ) + $a )); Please note that the ranges are with different steps. Here is the result: