Change the time zone in Codeigniter

前端 未结 7 1139
遇见更好的自我
遇见更好的自我 2021-01-11 10:37

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.

相关标签:
7条回答
  • 2021-01-11 10:41

    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'
    );
    
    0 讨论(0)
  • 2021-01-11 10:57

    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.

    0 讨论(0)
  • 2021-01-11 10:57
    date_default_timezone_set('Asia/Jakarta');
    

    Placing this in config.php. It works!

    0 讨论(0)
  • 2021-01-11 10:58

    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...
    
    0 讨论(0)
  • 2021-01-11 10:58

    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/

    0 讨论(0)
  • 2021-01-11 11:01

    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.

    0 讨论(0)
提交回复
热议问题