How to set the timezone for PHP?


 

If your PHP scripts do not show the correct time, the reason is that most probably your hosting server is in a different timezone. This can be easily resolved by changing a setting in PHP called date.timezone.

Depending on your location you can set a specific date.timezone value in PHP using the following option which should be added to your local file.
 

How to set PHP timezone?

1. Locate your php.ini file and edit it
* Note that the location of local php.ini is different depends on your server settings for example Windows server 2003 the location is C:\Windows\php.ini and Windows server 2008 C:\PHP\php.ini

2. Uncomment date.timezone as per following with the timezone from here that corresponds to the time you want to display
date.timezone = Asia/Kuala_Lumpur

3. Once you have entered the desired timezone, save the file

4. Now, you can check by creating phpinfo.php page by using below code to verify the on the changes.

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>


Comments