vipul sharma vipul sharma - 5 years ago 314
PHP Question

How to set time zone in code igniter?

I working on a php project using codeigniter. Please advise me what is the global way to set time zone for php and mysql . In which file i can set this. I want to set it without php.ini and htaccess file.

currently i am using this before every entry -:

date_default_timezone_set("Asia/Kolkata");
$time = Date('Y-m-d h:i:s');

Answer Source

Placing this date_default_timezone_set('Asia/Kolkata'); on config.php above base url also works

PHP List of Supported Time Zones

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

date_default_timezone_set('Asia/Kolkata');

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| If this is not set then CodeIgniter will try guess the protocol, domain
| and path to your installation. However, you should always configure this
| explicitly and never rely on auto-guessing, especially in production
| environments.
|
*/
$config['base_url'] = '';

// Codeigniter 3 Do not leave base url blank

$config['base_url'] = 'http://localhost/project/';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download