How to set date.timezone for CodeIgniter to work with php 5.3

后端 未结 5 1696
说谎
说谎 2020-12-13 09:57

When date.timezone in php.ini is commented out, it gives me:

A PHP Error was encountered

Severity: Warning

Message: main(): It

相关标签:
5条回答
  • 2020-12-13 10:12

    this is the simple way to do it

    $timezone = "Asia/Calcutta";
    if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
    //echo date('d-m-Y H:i:s');
    
    $localtime=date('H:i:s');
    
    $sql="INSERT INTO hits (ip,edate,curtime,page_name) VALUES ('$ip', CURDATE(),'$localtime','$filename') ";
    
    0 讨论(0)
  • 2020-12-13 10:16

    write in your index.php codeigniter...

    /*
    |---------------------------------------------------------------
    | TimeZone 
    |---------------------------------------------------------------
    |
    | default Time Zone
    | 
    
    */
    if ( function_exists( 'date_default_timezone_set' ) )
    date_default_timezone_set('Asia/Jakarta');
    

    Running well in my codeigniter

    0 讨论(0)
  • 2020-12-13 10:17

    If you Googled "CodeIgniter PHP 5.3" you would have found this article pretty quickly :)

    http://philsturgeon.co.uk/blog/2009/12/CodeIgniter-on-PHP-5.3

    To fix this, you only need to edit the main index.php for your CodeIgniter application:

    if( ! ini_get('date.timezone') )
    {
       date_default_timezone_set('GMT');
    } 
    

    This modification is something you will probably need to make for any CodeIgniter application running on PHP 5.3 and can easily be modified to your local timezone. There is a full list of supported timezones in the PHP manual here.

    0 讨论(0)
  • 2020-12-13 10:34

    date.timezone is intended to go in your php.ini or .htaccess file.

    you could do an ini_set('date.timezone', 'America/Los_Angeles'); in the first line of your script and get the desired results.

    0 讨论(0)
  • 2020-12-13 10:35

    Yes, if you cannot directly edit the php.ini file, placing...

    ini_set('date.timezone', 'America/New_York');
    

    ...as the first line in CI's index.php works fine.

    Reference: PHP's Available Timezones

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