Setting the Timezone for PHP in the PHP.Ini File

Setting the Timezone for PHP in the php.ini file

I tried all the other possible solutions posted, but none of them helped. This is what helped me save my timezone settings:

1) Go to your phpinfo() page and search for Loaded Configuration File and open the php.ini file mentioned under that section.

2) Change the default timezone settings by adding your new timezone by modifying this line: date.timezone=Asia/Kolkata.

3) Save the php.ini file and stop the Apache server.

4) Restart the Apache server. The timezone settings should now be modified.

Cannot Set date.timezone In php.ini file

finally solved my problem,
this is my Loaded Configuration File:

/etc/php5/apache2/php.ini 

modified the date.timezone here but it's not working.

So, I check the "Scan this dir for additional .ini files " values in phpinfo() which point to:

/etc/php5/apache2/conf.d 

then I search date.timezone from all files in that folder but found none.

this is my Additional .ini file parsed value in phpinfo():

/etc/php5/apache2/conf.d/05-opcache.ini, /etc/php5/apache2/conf.d/10-pdo.ini, /etc/php5/apache2/conf.d/20-json.ini, /etc/php5/apache2/conf.d/20-mysql.ini, /etc/php5/apache2/conf.d/20-mysqli.ini, /etc/php5/apache2/conf.d/20-pdo_mysql.ini, /etc/php5/apache2/conf.d/20-xdebug.ini, /etc/php5/apache2/conf.d/30-mcrypt.ini 

I modified /etc/php5/apache2/conf.d/20-xdebug.ini, and appended this line:

date.timezone = Asia/Jakarta

very weird but this solved my problem !!!

default time zone is not changing using php or php.ini

in php.ini

date.timezone="Asia/Riyadh"

and in my script

$nowtime = date("G:i:s");
$nowdate = date("Y-m-d");

Setting time zone in php

Function date_default_timezone_set()>= 5.1.0 set timezone globally.

If you need to set timezone locally, for specific variable, you can use DateTime>= 5.2.0 and DateTimezone>= 5.2.0 classes, like:

$dt = new DateTime('now', new DateTimezone('Asia/Dhaka'));
echo $dt->format('F j, Y, g:i a');

Here is the list of all available timezones in PHP.


Since non of the above functions will work on PHP version 4.x, you have no other way to set timezone, rather that setting your server time to your timezone, or add offset to time() functions, like:

echo date('F j, Y, g:i a', time() - 6*3600); # Bangladesh is in UTC+6


Related Topics



Leave a reply



Submit