The time-zone used and displayed by default under PHP is UTC (Coordinated Universal Time)… Hence why it might look so off from your system’s or server’s *local time-zone* time.
It’s sometimes best to leave the internal time-zone of PHP set to UTC (as it is a international time standard), and then convert (in PHP code) the UTC date-time value to whichever time-zone you’d like to utilize and display.
But if you really want PHP to use your specific *local* time-zone…
Setting PHP’s Global TimeZone via php.ini
You can tell PHP to use your time-zone by setting the proper value of “date.timezone” in php.ini.
Edit file:
C:\WampDeveloper\Config\Php\php.ini
Change this -
date.timezone = "UTC"
To this -
For West Cost:
date.timezone="America/Los_Angeles"
For East Cost:
date.timezone="America/New_York"
For Central Time:
date.timezone="America/Chicago"
Save file (and be careful not to change it’s extension when doing so). Restart Apache.
The list of time zones for PHP is here -
For America
For the rest of the World
Setting PHP’s Per-Website TimeZone via VirtualHost
You also have the option of leaving PHP’s global default on UTC (in php.ini), but changing it per-website…
Edit the website’s HTTP and HTTPS VirtualHost files (select website in WampDeveloper’s Websites Tab, click the VirtualHost buttons to open those files). Then within the <VirtualHost> block, insert -
<IfModule php5_module>
php_value date.timezone "America/New_York"
</IfModule>
Or use directive “php_admin_value” in the above line instead – if you don’t want any .htaccess files or PHP scripts in that website to be able to change that value at run-time.
Save the VirtualHost files. Restart Apache.
Note that this will only work if PHP is ran as an Apache module (mod_php), and not as a FCGI process (PHP-FCGI) because that process is separate from Apache and can’t be configured by it.
Setting PHP’s Per-Directory TimeZone via .htaccess
For setting the time-zone per PHP script’s folder/directory…
Just as mentioned above, instead of editing the VirtualHost files, edit the website’s .htaccess file and add in the proper “php_value” or “php_admin_value” directive.
Save the .htaccess file. There is no need to restart Apache after .htaccess edits.
In some cases, the time-zone might already be set there already.
This is the more portable way of setting the proper PHP values for your websites and scripts, but as mentioned above, those directives only work for mod_php and do not work for PHP-FCGI.
If you are running PHP-FCGI and don’t want to set global changes in php.ini, you may use the PHP function ini-set() to set your runtime values in script code.