my project is hosted on shared server and i want to change the timezone to Asia/Kolkata. i have tried setting timezone using htaccess file but failed.
Do it This Way
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'ci',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE,
'date_default_timezone_set' => 'Asia/Kolkata'
);
With CodeIgniter, the best place to set the timezone is inside the main index.php
file. It's at the same level in your project structure as the system/
and application/
folders.
Just add the following as the first line of code in the file after the opening <?php
tag:
date_default_timezone_set('Asia/Kolkata');
That should do it for all your PHP code.
Don't forget that if you're using a database, the timezone for the database will probably be different as well. If you're using MySQL, you'll want to do a SET time_zone = "+05:30"
query as soon as you open a database connection.
date_default_timezone_set('Asia/Jakarta');
Placing this in config.php. It works!
Another good practice is to put it in the CI_Controller class, right in the __construct function:
public function __construct() {
date_default_timezone_set( 'Asia/Kolkata' );
self::$instance =& $this;
// the rest of the code...
Please add the below code in the index.php file of the your Codeigniter project
datedefaulttimezoneset(‘Asia/Kolkata’);
Or You can also change using the php.ini file.
Also for more help visit http://www.tutorial-hub.com/top-interview-questions-and-answers-codeigniter-framework/
Try this
date_default_timezone_set('Asia/Kolkata');
in your index.php file. You don't need to have access to your php.ini file.